Merged V4.1-BUG-FIX to HEAD

42933: ALF-15328 could we add a sample log4j file in 'extension'? 
   42935: ALF-16455: Merged V3.4-BUG-FIX (3.4.12) to V4.1-BUG-FIX (4.1.2)
      42934: ALF-16454 TransformerDebug id values have gaps 
   42955: ALF-15328 could we add a sample log4j file in 'extension'?
      - missing j in file name
   42982: Merged DEV to V4.1-BUG-FIX
      42873: ALF-16194: Checkout/Checkin leaves Lockable aspect on which disables autoVersionOnUpdateProps
             DoNothingCopyBehaviourCallback policy has been set for lockable aspect (implemented in LockServiceImpl);
             Unit test has been added. 
   43000: Merged BRANCHES/DEV/BELARUS/V4.1-BUG-FIX-2012_10_19 to BRANCHES/DEV/V4.1-BUG-FIX:
      42936: ALF-11573: It's impossible to Modify settings for document versions
   43010: ALF-16006 MT: Document Library is absent after upgrade from 3.4.x to 4.1.x (eg. 3.4.10 -> 4.1.1)
      - applied patch suggested in JIRA
   43017: ALF-16457: "CmisObjectNotFoundException: No corresponding type found! Not a CMIS object?" thrown by AlfrescoCmisServiceImpl.getChildren
        - Check CMISNodeInfo for invalid type before processing.
   43019: ALF-14353: Upgrade Activiti dependencies in Maven build
   43022: ALF-14353: Upgrade Activiti dependencies in Maven build
   43027: Merged DEV to V4.1-BUG-FIX
       42426: ALF-15577: " does not support the method HEAD " when opening a MS Access file with "View In Browser"
   43029: Merged DEV to 4.1-BUG-FIX (4.1.2)
      42988: ALF-15791: Custom Types,Aspects defined with prefix using underscore cannot be loaded by API calls like api/classes/<type or aspect>
         Identical logic for old and new ClassDef API was moved to abstract super classes
      42924: ALF-15791: Custom Types,Aspects defined with prefix using underscore cannot be loaded by API calls like api/classes/<type or aspect>
         New set of URL templates for class defenitions were provided to support requests with separated namespace prefixes and names
   43031: ALF-16489: Typo in column-name of newly created index
   43041: Merged DEV to 4.1-BUG-FIX (4.1.2)
      43040: ALF-16425: API call to return all classes, returns wrong properties in classes
         Propertydefs and assocdefs are reordered to corelate with classdefs. Unit test was added for issue.
   43052: ALF-16194: Checkout/Checkin leaves Lockable aspect on which disables autoVersionOnUpdateProps
      - Fix failing test
   43055: Probable fix for ALF-15813. Replaced the 'skipCount' with the one in the query request, rather than query result.
   The Lucene query result does not support the reporting of the skipCount.
   43065: Merged V3.4-BUG-FIX to V4.1-BUG-FIX
      42958: ALF-14421: Inconsistencies when applying Versionable Aspect 
      - We think the most preferable fix that will result in the best consistency between Share and old Explorer behaviour is to make the adding of the versionable aspect always result in an initial MAJOR version, if a version type has not been specified. Major/minor versions can still be controlled explicitly by checkout/checkin the versionable aspect properties and the version service API.
      42998: ALF-14421: Fixed version label unit test fallout - back to what it used to be.
      42999: Fix for ALF-16261 - IE script error occurs when email space users providing there are no users in this space
      43006: Removed dependency on Apache Commons StringUtils. See ALF-12541, ALF-14254, AMZNSSS-17
      43028: ALF-14722: Merged V4.1-BUG-FIX to V3.4-BUG-FIX
         42902: Merged DEV to V4.1-BUG-FIX
            42519: ALF-13588: Google Doc failed to authenticate after incorrect password being entered for google account 
               Add ability to unregister class behaviours.
               Unregister googledocs behaviours when subsystem stops.
   43066: ALF-16502: Merged PATCHES/V4.0.2 to V4.1-BUG-FIX
      42969: Merged DEV to PATCHES/V4.0.2
         42967: MNT-158: SharePoint Protocol Opening Documents in Read-Only for Site Consumer with Collaborator Privileges
            Remove manual throwing of AccessDeniedException is user has "consumer" or "contributor" role.
            Create "links" container from system user.
   43067: Merged PATCHES/V4.1.1 to V4.1-BUG-FIX
      42470: ALF-16503 / ALF-16256: Upgrade 3.4.6 HF to 4.1.1 - DuplicateChildNodeNameException: Duplicate child name not allowed: surf-config 
      42591: ALF-16504 / ALF-16332: Fixed synchronization around org.alfresco.repo.dictionary.NamespaceDAOImpl.namespaceRegistryCache
      - There was no 'double checking' after releasing the write lock, meaning that under high concurrency lots of threads would queue up to continuously re-initialize the registry. 
      42705: ALF-16504/ ALF-16332, ALF-16377: Revisited synchronization and initialization of mutually-dependent DictionaryDAO and NamespaceDAO to prevent deadlock and simultaneous re-initialization in more than one thread
   43068: Merged DEV to V4.1-BUG-FIX
      - TODO: Update DB2 DDL in activiti
      42388: ALF-15828: DB2: unexpected index found in database.
      Modify activity create script for db2 to create normal name for ACT_HI_PROCINST.PROC_INST_ID_ index.
      Introduce patch that will rename autogenerated name to normal name for ACT_HI_PROCINST.PROC_INST_ID_ index.
      Update schema reference file for DB2.
      42429: ALF-15828: DB2: unexpected index found in database.
      Fix scripts from ALF-14983 and ALF-16038 to drop/recreate tables in DB2.
   43069: ALF-11214: IMAP subsystem is not successfully restarted after incorrect modification of IMAP properties via Admin Console
      Stopped ChildApplicationContextFactory from caching a stale application context that didn't successfully refresh.
   43071: ALF-13660: When using kerberos SSO, non domain explorer users requesting a download URL get a login page but after login do not get the requested document
   - Now the Web Client authentication filters use the same mechanism for preserving the request URL through a redirect to the login page
   43076: ALF-15828: Fixed merge issue
   43079: ALF-13602: Incorrect number of documents displayed in Share DocLib when a file is checked out
   - added ability for FileFolderService.list (-> FileFolder GetChildren CQ) to filter by one or more aspects, eg. cm:checkedOut
   43080: ALF-14421: More version label unit test fallout
   43092: Fix ALF-16460: Users may receive activity feed entries (from people they follow) for moderated sites to which they do not belong
   - also add unit test
   43093: Fix for ALF-16091 - Unable to inline edit javascript file.
   43096: Fix for ALF-16283 - When document is checked out, 'Edit Online' and 'Upload New Version' options should not be visible on the original document.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@43103 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Dave Ward
2012-10-25 16:38:22 +00:00
parent 6feaa5ecff
commit fe3fc5fff8
48 changed files with 3043 additions and 555 deletions

View File

@@ -0,0 +1,33 @@
<webscript>
<shortname>Head Content</shortname>
<description> Head method for the specified document.</description>
<!-- alfresco style -->
<!-- maybe need to add many paths, like in content.get.desc.xml -->
<url>/api/node/content{property}/{store_type}/{store_id}/{id}?a={attach?}&amp;streamId={streamId?}</url>
<args>
<arg>
<shortname>id</shortname>
<description>the node id of the object</description>
</arg>
<arg>
<shortname>property</shortname>
<description>the name of the content property to retrieve content from</description>
<default>cm:content</default>
</arg>
<arg>
<shortname>attach</shortname>
<description>if true, force download of content as attachment</description>
<default>false</default>
</arg>
<arg>
<shortname>streamId</shortname>
<description>if provided, download the rendition of the content as identified by the stream id</description>
</arg>
</args>
<format default="">argument</format>
<authentication>guest</authentication>
<transaction allow="readonly"/>
</webscript>

View File

@@ -0,0 +1,60 @@
<#macro assocDefJSON assocdefs>
<#escape x as jsonUtils.encodeJSONString(x)>
{
<#if assocdefs.name?exists>
"name" : "${assocdefs.name.toPrefixString()}",
</#if>
<#if assocdefs.title?exists>
"title" : "${assocdefs.title}",
<#else>
"title" : "",
</#if>
<#if assocdefs.description?exists>
"description" : "${assocdefs.description}",
<#else>
"description" : "",
</#if>
<#if assocdefs.isChild() == true>
"isChildAssociation" : true,
<#else>
"isChildAssociation" : false,
</#if>
<#if assocdefs.isProtected() == true>
"protected" : true,
<#else>
"protected" : false,
</#if>
"source" : {
<#if assocdefs.getSourceClass().name?exists>
"class" : "${assocdefs.getSourceClass().name.toPrefixString()}",
</#if>
<#if assocdefs.getSourceRoleName()?exists>
"role" : "${assocdefs.getSourceRoleName().toPrefixString()}",
</#if>
"mandatory" : ${assocdefs.isSourceMandatory()?string},
"many" : ${assocdefs.isSourceMany()?string}
},
"target" : {
<#if assocdefs.getTargetClass().name?exists>
"class" : "${assocdefs.getTargetClass().name.toPrefixString()}",
</#if>
<#if assocdefs.getTargetRoleName()?exists>
"role" : "${assocdefs.getTargetRoleName().toPrefixString()}",
</#if>
"mandatory" : ${assocdefs.isTargetMandatory()?string},
"many" : ${assocdefs.isTargetMany()?string}
},
<#if assocdefs.isChild() == true>
<#if assocdefs.getRequiredChildName()?exists>
"requiredChildName" : "${assocdefs.getRequiredChildName()}",
</#if>
<#if assocdefs.getDuplicateChildNamesAllowed() == true>
"duplicateChildNameAllowed" : true,
<#else>
"duplicateChildNameAllowed" : false,
</#if>
</#if>
"url" : "${"/api/defclasses/" + url.templateArgs.prefix + "/" + url.templateArgs.shortClassName + "/association/" + assocdefs.name.toPrefixString()?replace(":","/")}"
}
</#escape>
</#macro>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get association definitions</shortname>
<description>Get the collection of association definitions.</description>
<url>/api/defclasses/{prefix}/{shortClassName}/association/{assocprefix}/{assocname}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,6 @@
<#import "assocdefinition.lib.ftl" as assocDefLib/>
<#if assocdefs?exists>
<@assocDefLib.assocDefJSON assocdefs=assocdefs/>
<#else>
{}
</#if>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get association definitions for classname</shortname>
<description>Gets the collection of association definitions for a given classname.</description>
<url>/api/defclasses/{prefix}/{shortClassName}/associations?af={associationFilter?}&amp;nsp={namespacePrefix?}&amp;n={name?}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,14 @@
<#import "assocdefinition.lib.ftl" as assocDefLib/>
[
<#list assocdefs as assocdefs>
<#if individualproperty?exists>
<#if assocdefs.name == individualproperty.name>
<@assocDefLib.assocDefJSON assocdefs=assocdefs/>
<#break>
</#if>
<#else>
<@assocDefLib.assocDefJSON assocdefs=assocdefs/>
<#if assocdefs_has_next>,</#if>
</#if>
</#list>
]

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get class definitions for classname</shortname>
<description>Gets the collection of class definitions for a given classname.</description>
<url>/api/defclasses/{prefix}/{shortClassName}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,4 @@
<#import "classdetails.lib.ftl" as classdetailsDefLib/>
<#list classdefs as classdef>
<@classdetailsDefLib.classDefJSON classdef=classdef key=classdef_index/><#if classdef_has_next>,</#if>
</#list>

View File

@@ -0,0 +1,111 @@
<#macro classDefJSON classdef key>
<#local classdefprefix=classdef.name.toPrefixString()?replace(":","/")>
<#escape x as jsonUtils.encodeJSONString(x)>
{
<#if classdef.name??>"name": "${classdef.name.toPrefixString()}",</#if>
"isAspect": ${classdef.isAspect()?string},
"isContainer": ${classdef.isContainer()?string},
"title": "${classdef.title!""}",
"description": "${classdef.description!""}",
"parent":
{
<#if classdef.parentName??>
"name": "${classdef.parentName.toPrefixString()}",
"title": "${classdef.parentName.getLocalName()}",
"url": "/api/defclasses/${classdef.parentName.toPrefixString()?replace(":","/")}"
</#if>
},
"defaultAspects":
{
<#if classdef.defaultAspects??>
<#list classdef.defaultAspects as aspectdef>
"${aspectdef.name.toPrefixString()}":
{
"name": "${aspectdef.name.toPrefixString()}",
"title": "${aspectdef.title!""}",
"url": "/api/defclasses/${classdefprefix}/property/${aspectdef.name.toPrefixString()?replace(":","/")}"
}<#if aspectdef_has_next>,</#if>
</#list>
</#if>
},
"properties":
{
<#list propertydefs[key] as propertydef>
"${propertydef.name.toPrefixString()}":
{
"name": "${propertydef.name.toPrefixString()}",
"title": "${propertydef.title!""}",
"description": "${propertydef.description!""}",
"dataType": <#if propertydef.dataType??>"${propertydef.dataType.name.toPrefixString()}"<#else>"<unknown>"</#if>,
"defaultValue": <#if propertydef.defaultValue??>"${propertydef.defaultValue}"<#else>null</#if>,
"multiValued": ${propertydef.multiValued?string},
"mandatory": ${propertydef.mandatory?string},
"enforced": ${propertydef.mandatoryEnforced?string},
"protected": ${propertydef.protected?string},
"indexed": ${propertydef.indexed?string},
"url": "/api/defclasses/${classdefprefix}/property/${propertydef.name.toPrefixString()?replace(":","/")}"
}<#if propertydef_has_next>,</#if>
</#list>
},
"associations":
{
<#assign isfirst=true>
<#list assocdefs[key] as assocdef>
<#if !isfirst && !assocdef.isChild()>,</#if>
<#if !assocdef.isChild()>
<#assign isfirst=false>
"${assocdef.name.toPrefixString()}":
{
"name": "${assocdef.name.toPrefixString()}",
"title": "${assocdef.title!""}",
"url": "/api/defclasses/${classdefprefix}/association/${assocdef.name.toPrefixString()?replace(":","/")}",
"source":
{
<#if assocdef.getSourceClass().name??>"class": "${assocdef.getSourceClass().name.toPrefixString()}",</#if>
<#if assocdef.getSourceRoleName()??>"role": "${assocdef.getSourceRoleName().toPrefixString()}",</#if>
"mandatory": ${assocdef.isSourceMandatory()?string},
"many": ${assocdef.isSourceMany()?string}
},
"target":
{
<#if assocdef.getTargetClass().name??>"class": "${assocdef.getTargetClass().name.toPrefixString()}",</#if>
<#if assocdef.getTargetRoleName()??>"role": "${assocdef.getTargetRoleName().toPrefixString()}",</#if>
"mandatory": ${assocdef.isTargetMandatory()?string},
"many": ${assocdef.isTargetMany()?string}
}
}
</#if>
</#list>
},
"childassociations":
{
<#assign isfirst=true>
<#list assocdefs[key] as assocdef>
<#if !isfirst && assocdef.isChild()>,</#if>
<#if assocdef.isChild()>
<#assign isfirst=false>
"${assocdef.name.toPrefixString()}":
{
<#if assocdef.name??>"name": "${assocdef.name.toPrefixString()}",</#if>
"title": "${assocdef.title!""}",
"url": "/api/defclasses/${classdefprefix}/association/${assocdef.name.toPrefixString()?replace(":","/")}",
"source":
{
<#if assocdef.getSourceClass().name??>"class": "${assocdef.getSourceClass().name.toPrefixString()}",</#if>
"mandatory": ${assocdef.isSourceMandatory()?string},
"many": ${assocdef.isSourceMany()?string}
},
"target":
{
<#if assocdef.getTargetClass().name??>"class": "${assocdef.getTargetClass().name.toPrefixString()}",</#if>
"mandatory": ${assocdef.isTargetMandatory()?string},
"many": ${assocdef.isTargetMany()?string}
}
}
</#if>
</#list>
},
"url": "/api/defclasses/${classdefprefix}"
}
</#escape>
</#macro>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get class definitions</shortname>
<description>Gets the collection of class definitions - parameters classfilter , namespaceprefix and name.</description>
<url>/api/defclasses?cf={classFilter?}&amp;nsp={namespacePrefix?}&amp;n={name?}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,6 @@
<#import "classdetails.lib.ftl" as classdetailsDefLib/>
[
<#list classdefs as classdef>
<@classdetailsDefLib.classDefJSON classdef=classdef key=classdef_index/><#if classdef_has_next>,</#if>
</#list>
]

View File

@@ -0,0 +1,9 @@
<webscript>
<shortname>Get property definitions</shortname>
<description>Gets the collection of property definitions.</description>
<url>/api/defclasses/{prefix}/{shortClassName}/properties?nsp={namespacePrefix?}&amp;n={name?}</url>
<url>/api/defproperties?nsp={namespacePrefix?}&amp;n={name?}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,8 @@
<#import "propertydefinition.lib.ftl" as propertyDefLib/>
[
<#list propertydefs as propertydefinitions>
<@propertyDefLib.propertyDefJSON propertydefs=propertydefinitions/>
<#if propertydefinitions_has_next>,</#if>
</#list>
]

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get property definitions for classname</shortname>
<description>Gets the collection of property definitions for a given classname and property name.</description>
<url>/api/defclasses/{prefix}/{shortClassName}/property/{proppref}/{propname}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,6 @@
<#import "propertydefinition.lib.ftl" as propertyDefLib/>
<#if propertydefs?exists>
<@propertyDefLib.propertyDefJSON propertydefs=propertydefs/>
<#else>
{}
</#if>

View File

@@ -0,0 +1,46 @@
<#macro propertyDefJSON propertydefs>
<#escape x as jsonUtils.encodeJSONString(x)>
{
<#if propertydefs.name?exists>
"name" : "${propertydefs.name.toPrefixString()}",
</#if>
<#if propertydefs.title?exists>
"title" : "${propertydefs.title}",
</#if>
<#if propertydefs.description?exists>
"description" : "${propertydefs.description}",
</#if>
<#if propertydefs.defaultValues?exists>
"defaultValues" : "${propertydefs.defaultValues}",
<#else>
"defaultValues" : "",
</#if>
<#if propertydefs.dataType?exists>
"dataType" : "${propertydefs.dataType.name.toPrefixString()}",
</#if>
"multiValued" : ${propertydefs.multiValued?string},
"mandatory" : ${propertydefs.mandatory?string},
"enforced" : ${propertydefs.mandatoryEnforced?string},
"protected" : ${propertydefs.protected?string},
"indexed" : ${propertydefs.indexed?string},
"indexedAtomically" : ${propertydefs.indexedAtomically?string},
"constraints" :
[<#--
<#if propertydefs.constraints?exists>
<#list propertydefs.constraints as constraintdefs>
{
<#assign keys = constraintdefs.getConstraint()?keys>
<#list keys as key>
<#if key == "expression">
"${key}" : <#if constraintdefs.getConstraint()[key]?exists>"${constraintdefs.getConstraint()[key]}" <#else>"has no value"</#if>
</#if>
<#if key_has_next>,</#if>
</#list>
}<#if constraintdefs_has_next>,</#if>
</#list>
</#if>-->
],
"url" : "${"/api/property/" + propertydefs.name.toPrefixString()?replace(":","/")}"
}
</#escape>
</#macro>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get subclasses definitions</shortname>
<description>Get the collection of subclasses definitions - parameters r=> recursive, classfilter , namespaceprefix and name.</description>
<url>/api/defclasses/{prefix}/{shortClassName}/subclasses?r={recursive?}&amp;nsp={namespacePrefix?}&amp;n={name?}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,7 @@
<#import "classdetails.lib.ftl" as classdetailsDefLib/>
[
<#list classdefs as classdef>
<@classdetailsDefLib.classDefJSON classdef=classdef key=classdef_index/>
<#if classdef_has_next>,</#if>
</#list>
]

View File

@@ -20,7 +20,8 @@ var Filters =
"fm:forums",
"fm:forum",
"fm:topic",
"fm:post"
"fm:post",
"cm:checkedOut"
],
/**

View File

@@ -345,6 +345,15 @@
<property name="CMISRenditionService" ref="CMISRenditionService" />
</bean>
<!-- Content Info -->
<bean id="webscript.org.alfresco.cmis.content.head" class="org.alfresco.repo.web.scripts.content.ContentInfo" parent="webscript">
<property name="referenceFactory" ref="CMISReferenceFactory" />
<property name="permissionService" ref="PermissionService" />
<property name="nodeService" ref="NodeService" />
<property name="contentService" ref="ContentService" />
<property name="mimetypeService" ref="MimetypeService" />
</bean>
<!-- Content Write -->
<bean id="webscript.org.alfresco.cmis.content.put" class="org.alfresco.repo.web.scripts.content.ContentSet" parent="webscript">
<property name="referenceFactory" ref="CMISReferenceFactory" />
@@ -816,6 +825,15 @@
<property name="namespaceService" ref="NamespaceService"/>
</bean>
<!-- api with separated prefixes and names -->
<bean id="webscript.org.alfresco.repository.dictionary.prefixed.classes.get" class="org.alfresco.repo.web.scripts.dictionary.prefixed.ClassesGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.prefixed.class.get" class="org.alfresco.repo.web.scripts.dictionary.prefixed.ClassGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.prefixed.subclasses.get" class="org.alfresco.repo.web.scripts.dictionary.prefixed.SubClassesGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.prefixed.property.get" class="org.alfresco.repo.web.scripts.dictionary.prefixed.PropertyGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.prefixed.properties.get" class="org.alfresco.repo.web.scripts.dictionary.prefixed.PropertiesGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.prefixed.association.get" class="org.alfresco.repo.web.scripts.dictionary.prefixed.AssociationGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.prefixed.associations.get" class="org.alfresco.repo.web.scripts.dictionary.prefixed.AssociationsGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.classes.get" class="org.alfresco.repo.web.scripts.dictionary.ClassesGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.class.get" class="org.alfresco.repo.web.scripts.dictionary.ClassGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.subclasses.get" class="org.alfresco.repo.web.scripts.dictionary.SubClassesGet" parent="webscript.dictionary"/>

View File

@@ -0,0 +1,100 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited. This file is part of Alfresco Alfresco is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Alfresco is distributed in
* the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.content;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.cmis.CMISObjectReference;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.cmis.reference.ReferenceFactory;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
/**
* Content Info Service Get info about content from the Repository.
*
* @author alex.malinovsky
*/
public class ContentInfo extends StreamContent
{
private ReferenceFactory referenceFactory;
public void setReferenceFactory(ReferenceFactory referenceFactory)
{
this.referenceFactory = referenceFactory;
}
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
// create empty map of args
Map<String, String> args = new HashMap<String, String>(0, 1.0f);
// create map of template vars
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
// create object reference from url
CMISObjectReference reference = referenceFactory.createObjectReferenceFromUrl(args, templateVars);
NodeRef nodeRef = reference.getNodeRef();
if (nodeRef == null)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString());
}
// render content
QName propertyQName = ContentModel.PROP_CONTENT;
// Stream the content
streamContent(req, res, nodeRef, propertyQName, false);
}
@Override
protected void streamContentImpl(WebScriptRequest req, WebScriptResponse res, ContentReader reader, boolean attach, Date modified, String eTag, String attachFileName)
throws IOException
{
setAttachment(res, attach, attachFileName);
// establish mimetype
String mimetype = reader.getMimetype();
String extensionPath = req.getExtensionPath();
if (mimetype == null || mimetype.length() == 0)
{
mimetype = MimetypeMap.MIMETYPE_BINARY;
int extIndex = extensionPath.lastIndexOf('.');
if (extIndex != -1)
{
String ext = extensionPath.substring(extIndex + 1);
mimetype = mimetypeService.getMimetype(ext);
}
}
// set mimetype for the content and the character encoding + length for the stream
res.setContentType(mimetype);
res.setContentEncoding(reader.getEncoding());
res.setHeader("Content-Length", Long.toString(reader.getSize()));
// set caching
Cache cache = new Cache();
cache.setNeverCache(false);
cache.setMustRevalidate(true);
cache.setMaxAge(0L);
cache.setLastModified(modified);
cache.setETag(eTag);
res.setCache(cache);
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/*
* Webscript to get the Associationdefinition for a given classname and association-name
* @author Viachaslau Tsikhanovich
*/
public abstract class AbstractAssociationGet extends DictionaryWebServiceBase
{
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>(1);
QName classQname = getClassQname(req);
QName associationQname = getAssociationQname(req);
if (this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname) != null)
{
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname));
}
return model;
}
/**
* @param req - webscript request
* @return qualified name for association
*/
protected abstract QName getAssociationQname(WebScriptRequest req);
/**
* @param req - webscript request
* @return qualified name for class
*/
protected abstract QName getClassQname(WebScriptRequest req);
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Associationdefinitions for a given classname
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public abstract class AbstractAssociationsGet extends DictionaryWebServiceBase
{
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS = "individualproperty";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n";
private static final String REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER = "af";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String associationFilter = req.getParameter(REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
Map<String, Object> model = new HashMap<String, Object>();
Map<QName, AssociationDefinition> assocdef = new HashMap<QName, AssociationDefinition>();
QName associationQname = null;
QName classQname = getClassQname(req);
if(associationFilter == null)
{
associationFilter = "all";
}
//validate association filter
if(isValidAssociationFilter(associationFilter) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the associationFilter - " + associationFilter + " - parameter in the URL");
}
// validate for the presence of both name and namespaceprefix
if((name == null && namespacePrefix != null) ||
(name != null && namespacePrefix == null))
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing either name or namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
// check for association filters
if(associationFilter.equals("child"))
{
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getChildAssociations().values());
}
else if(associationFilter.equals("general"))
{
for(AssociationDefinition assocname:this.dictionaryservice.getClass(classQname).getAssociations().values())
{
if(assocname.isChild() == false)
{
assocdef.put(assocname.getName(), assocname);
}
}
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
}
else if(associationFilter.equals("all"))
{
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getAssociations().values());
}
// if both namespaceprefix and name parameters are given then, the combination namespaceprefix_name is used as the index to create the qname
if(name != null && namespacePrefix != null)
{
// validate the class combination namespaceprefix_name
associationQname = getAssociationQname(namespacePrefix, name);
if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname)== null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "not a Valid - namespaceprefix_name combination");
}
model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname));
}
return model;
}
/**
* @param req - webscript request
* @return qualified name for class
*/
protected abstract QName getClassQname(WebScriptRequest req);
/**
* @param req - webscript request
* @return qualified name for association
*/
protected abstract QName getAssociationQname(String namespacePrefix, String name);
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Classdefinitions for a classname eg. =>cm_author
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public abstract class AbstractClassGet extends DictionaryWebServiceBase
{
private static final String MODEL_PROP_KEY_CLASS_DETAILS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
Map<String, Object> model = new HashMap<String, Object>(3);
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
QName classQname = getClassQname(req);
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
model.put(MODEL_PROP_KEY_CLASS_DETAILS, classdef.values());
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
return model;
}
/**
* @param req - webscript request
* @return qualified name for class
*/
protected abstract QName getClassQname(WebScriptRequest req);
}

View File

@@ -0,0 +1,184 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Classdefinitions using classfilter , namespaceprefix and name
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public abstract class AbstractClassesGet extends DictionaryWebServiceBase
{
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String CLASS_FILTER_OPTION_TYPE1 = "all";
private static final String CLASS_FILTER_OPTION_TYPE2 = "aspect";
private static final String CLASS_FILTER_OPTION_TYPE3 = "type";
private static final String REQ_URL_TEMPL_VAR_CLASS_FILTER = "cf";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
Map<String, Object> model = new HashMap<String, Object>();
List<QName> qnames = new ArrayList<QName>();
QName classQname = null;
QName myModel = null;
// if classfilter is not given, then it defaults to all
if (classFilter == null)
{
classFilter = "all";
}
// validate classfilter
if (isValidClassFilter(classFilter) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL");
}
// name alone has no meaning without namespaceprefix
if (namespacePrefix == null && name != null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
// validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
if (namespacePrefix != null)
{
// validate name parameter if present along with the namespaceprefix
if (name != null)
{
classQname = getClassQname(namespacePrefix, name);
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
}
else
{
// if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
for (QName qnameObj : this.dictionaryservice.getAllModels())
{
if (qnameObj.getNamespaceURI().equals(namespaceUri))
{
name = qnameObj.getLocalName();
myModel = getQNameForModel(namespacePrefix, name);
// check the classfilter to pull out either all or type or aspects
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1))
{
qnames.addAll(this.dictionaryservice.getAspects(myModel));
qnames.addAll(this.dictionaryservice.getTypes(myModel));
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3))
{
qnames.addAll(this.dictionaryservice.getTypes(myModel));
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2))
{
qnames.addAll(this.dictionaryservice.getAspects(myModel));
}
}
}
}
}
// if namespacePrefix is null, then check the classfilter to pull out either all or type or aspects
if (myModel == null)
{
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1))
{
qnames.addAll(this.dictionaryservice.getAllAspects());
qnames.addAll(this.dictionaryservice.getAllTypes());
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3))
{
qnames.addAll(this.dictionaryservice.getAllTypes());
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2))
{
qnames.addAll(this.dictionaryservice.getAllAspects());
}
}
if (classdef.isEmpty() == true)
{
for (QName qnameObj : qnames)
{
classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
}
}
List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator());
model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, reorderedValues(classDefinitions, propdef));
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, reorderedValues(classDefinitions, assocdef));
return model;
}
/**
* @param namespacePrefix - namespace prefix of the class
* @param name - local name of the class
* @return qualified name for model
*/
protected abstract QName getQNameForModel(String namespacePrefix, String name);
/**
* @param req - webscript request
* @return qualified name for class
*/
protected abstract QName getClassQname(String namespacePrefix, String name);
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Propertydefinitions for a given classname eg. =>cm_person
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public abstract class AbstractPropertiesGet extends DictionaryWebServiceBase
{
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String PARAM_NAME = "name";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
QName classQName = getClassQName(req);
String[] names = req.getParameterValues(PARAM_NAME);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String namespaceURI = null;
if (namespacePrefix != null)
{
namespaceURI = this.namespaceService.getNamespaceURI(namespacePrefix);
}
Map<QName, PropertyDefinition> propMap = null;
if (classQName == null)
{
if (names != null)
{
propMap = new HashMap<QName, PropertyDefinition>(names.length);
for (String name : names)
{
QName propQName = QName.createQName(name, namespaceService);
PropertyDefinition propDef = dictionaryservice.getProperty(propQName);
if (propDef != null)
{
propMap.put(propQName, propDef);
}
}
}
else
{
Collection<QName> propQNames = dictionaryservice.getAllProperties(null);
propMap = new HashMap<QName, PropertyDefinition>(propQNames.size());
for (QName propQName : propQNames)
{
propMap.put(propQName, dictionaryservice.getProperty(propQName));
}
}
}
else
{
// Get all the property definitions for the class
propMap = dictionaryservice.getClass(classQName).getProperties();
}
// Filter the properties by URI
List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet())
{
if ((namespaceURI != null && namespaceURI.equals(entry.getKey().getNamespaceURI()) == true) || namespaceURI == null)
{
props.add(entry.getValue());
}
}
// Order property definitions by title
Collections.sort(props, new DictionaryComparators.PropertyDefinitionComparator());
// Pass list of property definitions to template
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
return model;
}
/**
* @param req - webscript request
* @return qualified name for class
*/
protected abstract QName getClassQName(WebScriptRequest req);
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Propertydefinition for a given classname and propname
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public abstract class AbstractPropertyGet extends DictionaryWebServiceBase
{
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>(1);
QName classQname = getClassQname(req);
QName propertyQname = getPropertyQname(req);
if (this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname) != null)
{
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname));
}
return model;
}
/**
* @param req - webscript request
* @return qualified name for property
*/
protected abstract QName getPropertyQname(WebScriptRequest req);
/**
* @param req - webscript request
* @return qualified name for class
*/
protected abstract QName getClassQname(WebScriptRequest req);
}

View File

@@ -0,0 +1,159 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Sub-Classdefinitions using classfilter , namespacePrefix and name
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public abstract class AbstractSubClassesGet extends DictionaryWebServiceBase
{
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN = "r";
// private static final String REQ_URL_TEMPL_VAR_CLASS_FILTER = "cf";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String recursiveValue = getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN));
boolean recursive = true;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
Map<String, Object> model = new HashMap<String, Object>();
String namespaceUri = null;
Collection<QName> qname = null;
boolean ignoreCheck = false;
// validate recursive parameter => can be either true or false or null
if (recursiveValue == null)
{
recursive = true;
}
else if (recursiveValue.equalsIgnoreCase("true"))
{
recursive = true;
}
else if (recursiveValue.equalsIgnoreCase("false"))
{
recursive = false;
}
else
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the value for the parameter recursive=> " + recursiveValue + " can only be either true or false");
}
qname = getQNameCollection(req, recursive);
// validate the name parameter
if (name != null)
{
if (isValidModelName(name) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name parameter - " + name + " in the URL");
}
}
// validate the name parameter
if (namespacePrefix == null && name != null)
{
namespaceUri = namespaceService.getNamespaceURI(getPrefixFromModelName(name));
}
if (namespacePrefix != null && name == null)
{
namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
}
if (namespacePrefix == null && name == null)
{
namespaceUri = null;
ignoreCheck = true;
}
if (namespacePrefix != null && name != null)
{
validateClassname(namespacePrefix, name);
namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
}
for (QName qnameObj : qname)
{
if ((ignoreCheck == true) || (qnameObj.getNamespaceURI().equals(namespaceUri)))
{
classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
}
}
List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator());
model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, reorderedValues(classDefinitions, propdef));
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, reorderedValues(classDefinitions, assocdef));
return model;
}
/**
* @param req - webscript request
* @param recursive - flag to get SubAspects or SubTypes recursively
* @return collection of qualified names for subclasses
*/
protected abstract Collection<QName> getQNameCollection(WebScriptRequest req, boolean recursive);
/**
* Throws WebScriptException if classname is invalid
* @param namespacePrefix - namespace prefix of a class
* @param name - localname of a class
*/
protected abstract void validateClassname(String namespacePrefix, String name);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,36 +18,37 @@
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/*
* Webscript to get the Associationdefinition for a given classname and association-name
* @author Saravanan Sellathurai
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class AssociationGet extends DictionaryWebServiceBase
public class AssociationGet extends AbstractAssociationGet
{
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String DICTIONARY_CLASS_NAME = "classname";
private static final String DICTIONARY_ASSOCIATION_NAME = "assocname";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
@Override
protected QName getAssociationQname(WebScriptRequest req)
{
String associationName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_NAME);
if(associationName == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association name in the URL");
}
return QName.createQName(getFullNamespaceURI(associationName));
}
@Override
protected QName getClassQname(WebScriptRequest req)
{
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
String associationName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_NAME);
Map<String, Object> model = new HashMap<String, Object>(1);
QName classQname = null;
QName associationQname = null;
// validate the classname
if (isValidClassname(className) == false)
@@ -55,21 +56,7 @@ public class AssociationGet extends DictionaryWebServiceBase
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL");
}
classQname = QName.createQName(getFullNamespaceURI(className));
if(associationName == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association name in the URL");
}
associationQname = QName.createQName(getFullNamespaceURI(associationName));
if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname) != null)
{
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname));
}
return model;
return QName.createQName(getFullNamespaceURI(className));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,110 +18,36 @@
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Associationdefinitions for a given classname
* @author Saravanan Sellathurai
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class AssociationsGet extends DictionaryWebServiceBase
public class AssociationsGet extends AbstractAssociationsGet
{
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS = "individualproperty";
private static final String DICTIONARY_CLASS_NAME = "classname";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n";
private static final String REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER = "af";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
@Override
protected QName getClassQname(WebScriptRequest req)
{
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
String associationFilter = req.getParameter(REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
Map<String, Object> model = new HashMap<String, Object>();
Map<QName, AssociationDefinition> assocdef = new HashMap<QName, AssociationDefinition>();
QName associationQname = null;
QName classQname = null;
if(associationFilter == null)
{
associationFilter = "all";
}
//validate association filter
if(isValidAssociationFilter(associationFilter) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the associationFilter - " + associationFilter + " - parameter in the URL");
}
//validate classname
if(isValidClassname(className) == true)
{
classQname = QName.createQName(getFullNamespaceURI(className));
}
else
if (isValidClassname(className) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL");
}
// validate for the presence of both name and namespaceprefix
if((name == null && namespacePrefix != null) ||
(name != null && namespacePrefix == null))
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing either name or namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
return QName.createQName(getFullNamespaceURI(className));
}
// check for association filters
if(associationFilter.equals("child"))
@Override
protected QName getAssociationQname(String namespacePrefix, String name)
{
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getChildAssociations().values());
}
else if(associationFilter.equals("general"))
{
for(AssociationDefinition assocname:this.dictionaryservice.getClass(classQname).getAssociations().values())
{
if(assocname.isChild() == false)
{
assocdef.put(assocname.getName(), assocname);
}
}
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
}
else if(associationFilter.equals("all"))
{
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getAssociations().values());
}
// if both namespaceprefix and name parameters are given then, the combination namespaceprefix_name is used as the index to create the qname
if(name != null && namespacePrefix != null)
{
// validate the class combination namespaceprefix_name
associationQname = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname)== null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "not a Valid - namespaceprefix_name combination");
}
model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname));
}
return model;
return QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,13 +18,6 @@
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
@@ -32,48 +25,26 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Classdefinitions for a classname eg. =>cm_author
* @author Saravanan Sellathurai
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class ClassGet extends DictionaryWebServiceBase
public class ClassGet extends AbstractClassGet
{
private static final String MODEL_PROP_KEY_CLASS_DETAILS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String DICTIONARY_CLASS_NAME = "className";
/**
* @Override method from DeclarativeWebScript
* @Override method from AbstractClassGet
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
@Override
protected QName getClassQname(WebScriptRequest req)
{
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
Map<String, Object> model = new HashMap<String, Object>(3);
QName classQname = null;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
//validate the classname and throw appropriate error message
if(isValidClassname(className) == true)
{
classQname = QName.createQName(getFullNamespaceURI(className));
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
}
else
if (isValidClassname(className) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL");
}
model.put(MODEL_PROP_KEY_CLASS_DETAILS, classdef.values());
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
return model;
return QName.createQName(getFullNamespaceURI(className));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,159 +18,33 @@
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Classdefinitions using classfilter , namespaceprefix and name
* @author Saravanan Sellathurai
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class ClassesGet extends DictionaryWebServiceBase
public class ClassesGet extends AbstractClassesGet
{
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String CLASS_FILTER_OPTION_TYPE1 = "all";
private static final String CLASS_FILTER_OPTION_TYPE2 = "aspect";
private static final String CLASS_FILTER_OPTION_TYPE3 = "type";
private static final String REQ_URL_TEMPL_VAR_CLASS_FILTER = "cf";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
@Override
protected QName getQNameForModel(String namespacePrefix, String name)
{
String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
String className = null;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
Map<String, Object> model = new HashMap<String, Object>();
List<QName> qnames = new ArrayList<QName>();
QName classQname = null;
QName myModel = null;
//if classfilter is not given, then it defaults to all
if(classFilter == null)
{
classFilter = "all";
return QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
}
//validate classfilter
if(isValidClassFilter(classFilter) == false)
@Override
protected QName getClassQname(String namespacePrefix, String name)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL");
}
//name alone has no meaning without namespaceprefix
if(namespacePrefix == null && name != null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
//validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
if(namespacePrefix != null)
{
//validate name parameter if present along with the namespaceprefix
if(name != null)
{
className = namespacePrefix + "_" + name;
String className = namespacePrefix + "_" + name;
if(isValidClassname(className) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL");
}
classQname = QName.createQName(getFullNamespaceURI(className));
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
}
else
{
//if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
for(QName qnameObj:this.dictionaryservice.getAllModels())
{
if(qnameObj.getNamespaceURI().equals(namespaceUri))
{
name = qnameObj.getLocalName();
myModel = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
// check the classfilter to pull out either all or type or aspects
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1))
{
qnames.addAll(this.dictionaryservice.getAspects(myModel));
qnames.addAll(this.dictionaryservice.getTypes(myModel));
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3))
{
qnames.addAll(this.dictionaryservice.getTypes(myModel));
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2))
{
qnames.addAll(this.dictionaryservice.getAspects(myModel));
}
}
}
}
}
// if namespacePrefix is null, then check the classfilter to pull out either all or type or aspects
if(myModel == null)
{
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1))
{
qnames.addAll(this.dictionaryservice.getAllAspects());
qnames.addAll(this.dictionaryservice.getAllTypes());
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3))
{
qnames.addAll(this.dictionaryservice.getAllTypes());
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2))
{
qnames.addAll(this.dictionaryservice.getAllAspects());
}
}
if(classdef.isEmpty() == true)
{
for(QName qnameObj: qnames)
{
classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
}
}
List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator());
model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
return model;
return QName.createQName(getFullNamespaceURI(className));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -21,7 +21,10 @@ package org.alfresco.repo.web.scripts.dictionary;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
@@ -175,6 +178,66 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
//assertEquals(2, result.getJSONObject("associations").length());
}
private void validatePropertiesConformity(JSONArray classDefs) throws Exception
{
final int itemsToTest = 10;
for (int i = 0; (i < itemsToTest) && (i < classDefs.length()); ++i)
{
JSONObject classDef1 = classDefs.getJSONObject(i);
JSONArray propertyNames1 = classDef1.getJSONObject("properties").names();
// properties of class obtained by api/classes
List<String> propertyValues1 = Collections.emptyList();
if (propertyNames1 != null)
{
propertyValues1 = new ArrayList<String>(propertyNames1.length());
for (int j = 0; j < propertyNames1.length(); j++)
{
propertyValues1.add(propertyNames1.getString(j));
}
}
String classUrl = classDef1.getString("url");
assertTrue(classUrl.contains(URL_SITES));
Response responseFromGetClassDef = sendRequest(new GetRequest(classUrl), 200);
JSONObject classDef2 = new JSONObject(responseFromGetClassDef.getContentAsString());
assertTrue(classDef2.length() > 0);
assertEquals(200, responseFromGetClassDef.getStatus());
assertEquals(classDef1.getString("name"), classDef2.getString("name"));
JSONArray propertyNames2 = classDef2.getJSONObject("properties").names();
// properties of class obtained by api/classes/class
List<String> propertyValues2 = Collections.emptyList();
if (propertyNames2 != null)
{
propertyValues2 = new ArrayList<String>(propertyNames2.length());
for (int j = 0; j < propertyNames2.length(); j++)
{
propertyValues2.add(propertyNames2.getString(j));
}
}
Response responseFromGetPropertiesDef = sendRequest(new GetRequest(classUrl + "/properties"), 200);
JSONArray propertiesDefs = new JSONArray(responseFromGetPropertiesDef.getContentAsString());
assertEquals(200, responseFromGetClassDef.getStatus());
// properties of class obtained by api/classes/class/properties
List<String> propertyValues3 = new ArrayList<String>(propertiesDefs.length());
for (int j = 0; j < propertiesDefs.length(); j++)
{
propertyValues3.add(propertiesDefs.getJSONObject(j).getString("name"));
}
assertEquivalenceProperties(propertyValues1, propertyValues2);
assertEquivalenceProperties(propertyValues2, propertyValues3);
}
}
private void assertEquivalenceProperties(List<String> propertyValues1, List<String> propertyValues2)
{
if ((propertyValues1.size() != propertyValues2.size()) || !propertyValues1.containsAll(propertyValues2))
{
fail("Wrong properties in classes");
}
}
public void testGetPropertyDef() throws Exception
{
Response response = sendRequest(new GetRequest("/api/classes/cm_auditable/property/cm_created"), 200);
@@ -948,4 +1011,15 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
}
public void testGetClasses() throws Exception
{
GetRequest req = new GetRequest(URL_SITES);
Response response = sendRequest(req, 200);
JSONArray result = new JSONArray(response.getContentAsString());
assertTrue(result.length() > 0);
assertEquals(200, response.getStatus());
validatePropertiesConformity(result);
}
}

View File

@@ -18,8 +18,12 @@
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.InvalidQNameException;
import org.alfresco.service.namespace.NamespaceService;
@@ -95,6 +99,26 @@ public abstract class DictionaryWebServiceBase extends DeclarativeWebScript
return result;
}
/**
* @param prefix - prefix for class name
* @param shortName - short class name
* @return qualified name for class name
*/
protected QName createClassQName(String prefix, String shortName)
{
QName result = null;
String url = namespaceService.getNamespaceURI(prefix);
if (url != null && url.length() != 0 && shortName != null && shortName.length() != 0)
{
QName classQName = QName.createQName(url, shortName);
if (dictionaryservice.getClass(classQName) != null)
{
result = classQName;
}
}
return result;
}
/**
* @param qname
@@ -126,6 +150,26 @@ public abstract class DictionaryWebServiceBase extends DeclarativeWebScript
}
}
/**
* @param prefix prefix for classname as cm
* @param shorname the short class name as person
* @return String the full name in the following format {namespaceuri}shorname
*/
public String getFullNamespaceURI(String prefix, String shorname)
{
try
{
String result = null;
String url = this.namespaceService.getNamespaceURI(prefix);
result = "{" + url + "}" + shorname;
return result;
}
catch (Exception e)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact classname - " + prefix + ":" + shorname + " parameter has not been provided in the URL");
}
}
/**
* @param classname - checks whether the classname is valid , gets the classname as input e.g cm_person
* @return true - if the class is valid , false - if the class is invalid
@@ -145,6 +189,27 @@ public abstract class DictionaryWebServiceBase extends DeclarativeWebScript
return false;
}
/**
* Checks whether the classname is valid
* @param prefix - gets the prefix as input e.g cm
* @param shorname - gets the short classname as input e.g person
* @return true - if the class is valid , false - if the class is invalid
*/
public boolean isValidClassname(String prefix, String shorname)
{
QName qname = null;
try
{
qname = QName.createQName(this.getFullNamespaceURI(prefix, shorname));
return (dictionaryservice.getClass(qname) != null);
}
catch (InvalidQNameException e)
{
//just ignore
}
return false;
}
/**
* @param namespaceprefix - gets a valid namespaceprefix as input
* @return modelname from namespaceprefix - returns null if invalid namespaceprefix is given
@@ -193,6 +258,26 @@ public abstract class DictionaryWebServiceBase extends DeclarativeWebScript
return false;
}
/**
* @param prefix as the input
* @param shorname as the input
* @return true if it is a aspect or false if it is a Type
*/
public boolean isValidTypeorAspect(String prefix, String shorname)
{
try
{
QName qname = QName.createQName(this.getFullNamespaceURI(prefix, shorname));
return ((this.dictionaryservice.getClass(qname) != null) &&
(this.dictionaryservice.getClass(qname).isAspect()));
}
catch (InvalidQNameException e)
{
// ignore
}
return false;
}
/**
* @param modelname - gets the modelname as the input (modelname is without prefix ie. cm:contentmodel => where modelname = contentmodel)
* @return true if valid or false
@@ -269,4 +354,21 @@ public abstract class DictionaryWebServiceBase extends DeclarativeWebScript
classfilter.equals(CLASS_FILTER_OPTION_TYPE3));
}
/**
* Returns dependent collections (properties or associations)
* in order that complies to order of class definitions
* @param sortedClassDefs - list of sorted class definitions
* @param dependent - collections that depend on class definitions
* @return collection of dependent values
*/
protected <T> Collection<T> reorderedValues(List<ClassDefinition> sortedClassDefs, Map<QName, T> dependent)
{
Collection<T> result = new ArrayList<T>(sortedClassDefs.size());
for (ClassDefinition classDef : sortedClassDefs)
{
result.add(dependent.get(classDef.getName()));
}
return result;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,38 +18,23 @@
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
*
* Webscript to get the Propertydefinitions for a given classname eg. =>cm_person
*
* @author Saravanan Sellathurai
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class PropertiesGet extends DictionaryWebServiceBase
public class PropertiesGet extends AbstractPropertiesGet
{
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String DICTIONARY_CLASS_NAME = "classname";
private static final String PARAM_NAME = "name";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
@Override
protected QName getClassQName(WebScriptRequest req)
{
QName classQName = null;
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
@@ -62,71 +47,7 @@ public class PropertiesGet extends DictionaryWebServiceBase
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
}
}
String[] names = req.getParameterValues(PARAM_NAME);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String namespaceURI = null;
if (namespacePrefix != null)
{
namespaceURI = this.namespaceService.getNamespaceURI(namespacePrefix);
}
Map<QName, PropertyDefinition> propMap = null;
if (classQName == null)
{
if (names != null)
{
propMap = new HashMap<QName, PropertyDefinition>(names.length);
for (String name : names)
{
QName propQName = QName.createQName(name, namespaceService);
PropertyDefinition propDef = dictionaryservice.getProperty(propQName);
if (propDef != null)
{
propMap.put(propQName, propDef);
}
}
}
else
{
Collection<QName> propQNames = dictionaryservice.getAllProperties(null);
propMap = new HashMap<QName, PropertyDefinition>(propQNames.size());
for (QName propQName : propQNames)
{
propMap.put(propQName, dictionaryservice.getProperty(propQName));
}
return classQName;
}
}
else
{
// Get all the property definitions for the class
propMap = dictionaryservice.getClass(classQName).getProperties();
}
// Filter the properties by URI
List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet())
{
if ((namespaceURI != null &&
namespaceURI.equals(entry.getKey().getNamespaceURI()) == true) ||
namespaceURI == null)
{
props.add(entry.getValue());
}
}
// Order property definitions by title
Collections.sort(props, new DictionaryComparators.PropertyDefinitionComparator());
// Pass list of property definitions to template
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
return model;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,11 +18,7 @@
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
@@ -30,25 +26,31 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Propertydefinition for a given classname and propname
*
* @author Saravanan Sellathurai
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class PropertyGet extends DictionaryWebServiceBase
public class PropertyGet extends AbstractPropertyGet
{
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String DICTIONARY_CLASS_NAME = "classname";
private static final String DICTIONARY_PROPERTY_NAME = "propname";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
@Override
protected QName getPropertyQname(WebScriptRequest req)
{
String propertyName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PROPERTY_NAME);
//validate the presence of property name
if(propertyName == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter propertyname in the URL");
}
return QName.createQName(getFullNamespaceURI(propertyName));
}
@Override
protected QName getClassQname(WebScriptRequest req)
{
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
String propertyName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PROPERTY_NAME);
Map<String, Object> model = new HashMap<String, Object>(1);
QName classQname = null;
QName propertyQname = null;
// validate the classname
if (isValidClassname(className) == false)
@@ -56,23 +58,7 @@ public class PropertyGet extends DictionaryWebServiceBase
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL");
}
classQname = QName.createQName(getFullNamespaceURI(className));
//validate the presence of property name
if(propertyName == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter propertyname in the URL");
}
propertyQname = QName.createQName(getFullNamespaceURI(propertyName));
if(this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname) != null)
{
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname));
}
return model;
return QName.createQName(getFullNamespaceURI(className));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,18 +18,9 @@
*/
package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
@@ -37,61 +28,19 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Sub-Classdefinitions using classfilter , namespacePrefix and name
*
* @author Saravanan Sellathurai
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class SubClassesGet extends DictionaryWebServiceBase
public class SubClassesGet extends AbstractSubClassesGet
{
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN = "r";
//private static final String REQ_URL_TEMPL_VAR_CLASS_FILTER = "cf";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n";
private static final String DICTIONARY_CLASS_NAME = "classname";
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
@Override
protected Collection<QName> getQNameCollection(WebScriptRequest req, boolean recursive)
{
String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
String recursiveValue = getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN));
boolean recursive = true;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
Map<String, Object> model = new HashMap<String, Object>();
QName classQName = null;
String namespaceUri = null;
Collection <QName> qname = null;
boolean isAspect = false;
boolean ignoreCheck = false;
// validate recursive parameter => can be either true or false or null
if(recursiveValue == null)
{
recursive = true;
}
else if(recursiveValue.equalsIgnoreCase("true"))
{
recursive = true;
}
else if (recursiveValue.equalsIgnoreCase("false"))
{
recursive = false;
}
else
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the value for the parameter recursive=> " + recursiveValue +" can only be either true or false");
}
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
//validate the className
if(isValidClassname(className) == true)
@@ -110,66 +59,21 @@ public class SubClassesGet extends DictionaryWebServiceBase
// collect the subaspects or subtypes of the class
if(isAspect == true)
{
qname = this.dictionaryservice.getSubAspects(classQName, recursive);
return this.dictionaryservice.getSubAspects(classQName, recursive);
}
else
{
qname = this.dictionaryservice.getSubTypes(classQName, recursive);
}
//validate the name parameter
if(name != null)
{
if(isValidModelName(name) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name parameter - " + name + " in the URL");
return this.dictionaryservice.getSubTypes(classQName, recursive);
}
}
//validate the name parameter
if (namespacePrefix == null && name != null)
{
namespaceUri = namespaceService.getNamespaceURI(getPrefixFromModelName(name));
}
if (namespacePrefix != null && name == null)
{
namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
}
if(namespacePrefix == null && name == null)
{
namespaceUri = null;
ignoreCheck = true;
}
if (namespacePrefix != null && name != null)
@Override
protected void validateClassname(String namespacePrefix, String name)
{
if(isValidClassname(namespacePrefix + "_" + name) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespacePrefix - " + namespacePrefix + " and name - "+ name + " - parameter in the URL");
}
namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
}
for(QName qnameObj: qname)
{
if((ignoreCheck == true) ||
(qnameObj.getNamespaceURI().equals(namespaceUri)))
{
classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
}
}
List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator());
model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
return model;
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary.prefixed;
import org.alfresco.repo.web.scripts.dictionary.AbstractAssociationGet;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/*
* Webscript to get the Associationdefinition for a given classname and association-name
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class AssociationGet extends AbstractAssociationGet
{
private static final String DICTIONARY_PREFIX = "prefix";
private static final String DICTIONARY_SHORT_CLASS_NAME = "shortClassName";
private static final String DICTIONARY_ASSOCIATION_PREFIX = "assocprefix";
private static final String DICTIONARY_ASSOCIATION_SHORTNAME = "assocname";
@Override
protected QName getClassQname(WebScriptRequest req)
{
String classPrefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PREFIX);
String shortClassName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORT_CLASS_NAME);
//validate the classname
if(isValidClassname(classPrefix, shortClassName) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + classPrefix + ":" + shortClassName + " - parameter in the URL");
}
return QName.createQName(getFullNamespaceURI(classPrefix, shortClassName));
}
@Override
protected QName getAssociationQname(WebScriptRequest req)
{
String associationName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_SHORTNAME);
String associationPrefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_PREFIX);
if(associationPrefix == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association prefix in the URL");
}
if(associationName == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association name in the URL");
}
return QName.createQName(getFullNamespaceURI(associationPrefix, associationName));
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary.prefixed;
import org.alfresco.repo.web.scripts.dictionary.AbstractAssociationsGet;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Associationdefinitions for a given classname
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class AssociationsGet extends AbstractAssociationsGet
{
private static final String DICTIONARY_PREFIX = "prefix";
private static final String DICTIONARY_SHORT_CLASS_NAME = "shortClassName";
@Override
protected QName getClassQname(WebScriptRequest req)
{
String prefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PREFIX);
String shortClassName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORT_CLASS_NAME);
//validate classname
if (isValidClassname(prefix, shortClassName) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + prefix + ":" + shortClassName + " - parameter in the URL");
}
return QName.createQName(getFullNamespaceURI(prefix, shortClassName));
}
@Override
protected QName getAssociationQname(String namespacePrefix, String name)
{
return QName.createQName(getFullNamespaceURI(namespacePrefix, name));
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary.prefixed;
import org.alfresco.repo.web.scripts.dictionary.AbstractClassGet;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Classdefinitions for a classname eg. =>cm_author
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class ClassGet extends AbstractClassGet
{
private static final String DICTIONARY_PREFIX = "prefix";
private static final String DICTIONARY_SHORT_CLASS_NAME = "shortClassName";
/**
* @Override method from AbstractClassGet
*/
@Override
protected QName getClassQname(WebScriptRequest req)
{
String prefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PREFIX);
String shortName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORT_CLASS_NAME);
//validate the classname and throw appropriate error message
if (isValidClassname(prefix, shortName) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + prefix + ":" + shortName + " - parameter in the URL");
}
return QName.createQName(getFullNamespaceURI(prefix, shortName));
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary.prefixed;
import org.alfresco.repo.web.scripts.dictionary.AbstractClassesGet;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
/**
* Webscript to get the Classdefinitions using classfilter , namespaceprefix and name
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class ClassesGet extends AbstractClassesGet
{
@Override
protected QName getQNameForModel(String namespacePrefix, String name)
{
return QName.createQName(getFullNamespaceURI(namespacePrefix, name));
}
@Override
protected QName getClassQname(String namespacePrefix, String name)
{
if(isValidClassname(namespacePrefix, name) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL");
}
return QName.createQName(getFullNamespaceURI(namespacePrefix, name));
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary.prefixed;
import org.alfresco.repo.web.scripts.dictionary.AbstractPropertiesGet;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Propertydefinitions for a given classname eg. =>cm_person
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class PropertiesGet extends AbstractPropertiesGet
{
private static final String DICTIONARY_PREFIX = "prefix";
private static final String DICTIONARY_SHORT_CLASS_NAME = "shortClassName";
@Override
protected QName getClassQName(WebScriptRequest req)
{
QName classQName = null;
String prefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PREFIX);
String shortName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORT_CLASS_NAME);
if (prefix != null && prefix.length() != 0 && shortName != null && shortName.length()!= 0)
{
classQName = createClassQName(prefix, shortName);
if (classQName == null)
{
// Error
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + prefix + ":" + shortName + " - parameter in the URL");
}
}
return classQName;
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary.prefixed;
import org.alfresco.repo.web.scripts.dictionary.AbstractPropertyGet;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Propertydefinition for a given classname and propname
*
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class PropertyGet extends AbstractPropertyGet
{
private static final String DICTIONARY_PREFIX = "prefix";
private static final String DICTIONARY_SHORT_CLASS_NAME = "shortClassName";
private static final String DICTIONARY_SHORTPROPERTY_NAME = "propname";
private static final String DICTIONARY_PROPERTY_FREFIX = "proppref";
@Override
protected QName getPropertyQname(WebScriptRequest req)
{
String propertyName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORTPROPERTY_NAME);
String propertyPrefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PROPERTY_FREFIX);
//validate the presence of property name
if(propertyName == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter short propertyname in the URL");
}
//validate the presence of property prefix
if(propertyPrefix == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter propertyprefix in the URL");
}
return QName.createQName(getFullNamespaceURI(propertyPrefix, propertyName));
}
@Override
protected QName getClassQname(WebScriptRequest req)
{
String prefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PREFIX);
String shortClassName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORT_CLASS_NAME);
// validate the classname
if (isValidClassname(prefix, shortClassName) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + prefix + ":" + shortClassName + " - parameter in the URL");
}
return QName.createQName(getFullNamespaceURI(prefix, shortClassName));
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.dictionary.prefixed;
import java.util.Collection;
import org.alfresco.repo.web.scripts.dictionary.AbstractSubClassesGet;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Sub-Classdefinitions using classfilter , namespacePrefix and name
* @author Saravanan Sellathurai, Viachaslau Tsikhanovich
*/
public class SubClassesGet extends AbstractSubClassesGet
{
private static final String DICTIONARY_PREFIX = "prefix";
private static final String DICTIONARY_CLASS_SHORTNAME = "shortClassName";
@Override
protected Collection<QName> getQNameCollection(WebScriptRequest req, boolean recursive)
{
String prefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PREFIX);
String shortClassName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_SHORTNAME);
QName classQName = null;
boolean isAspect = false;
//validate the className
if(isValidClassname(prefix, shortClassName) == true)
{
classQName = QName.createQName(getFullNamespaceURI(prefix, shortClassName));
if(isValidTypeorAspect(prefix, shortClassName) == true)
{
isAspect = true;
}
}
else
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + prefix + ":" + shortClassName + " parameter in the URL");
}
// collect the subaspects or subtypes of the class
if(isAspect == true)
{
return this.dictionaryservice.getSubAspects(classQName, recursive);
}
else
{
return this.dictionaryservice.getSubTypes(classQName, recursive);
}
}
@Override
protected void validateClassname(String namespacePrefix, String name)
{
if(isValidClassname(namespacePrefix, name) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespacePrefix - " + namespacePrefix + " and name - "+ name + " - parameter in the URL");
}
}
}

View File

@@ -620,7 +620,7 @@ public abstract class BaseKerberosAuthenticationFilter extends BaseSSOAuthentica
// Force the logon to start again
resp.setHeader("WWW-Authenticate", "Negotiate");
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
writeLoginPageLink(req, resp);
writeLoginPageLink(context, req, resp);
resp.flushBuffer();
}

View File

@@ -267,7 +267,7 @@ public abstract class BaseNTLMAuthenticationFilter extends BaseSSOAuthentication
// Send back a request for NTLM authentication
sresp.setHeader(WWW_AUTHENTICATE, AUTH_NTLM);
sresp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
writeLoginPageLink(sreq, sresp);
writeLoginPageLink(context, sreq, sresp);
sresp.flushBuffer();
return false;
}
@@ -1033,7 +1033,7 @@ public abstract class BaseNTLMAuthenticationFilter extends BaseSSOAuthentication
// Force the logon to start again
res.setHeader(WWW_AUTHENTICATE, AUTH_NTLM);
res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
writeLoginPageLink(req, res);
writeLoginPageLink(context, req, res);
}
res.flushBuffer();
}

View File

@@ -523,11 +523,12 @@ public abstract class BaseSSOAuthenticationFilter extends BaseAuthenticationFilt
* Writes link to login page and refresh tag which cause user
* to be redirected to the login page.
*
* @param context ServletContext
* @param resp HttpServletResponse
* @param httpSess HttpSession
* @throws IOException
*/
protected void writeLoginPageLink(HttpServletRequest req, HttpServletResponse resp) throws IOException
protected void writeLoginPageLink(ServletContext context, HttpServletRequest req, HttpServletResponse resp) throws IOException
{
if ( hasLoginPage())
{