04-12-2013 01:50 PM
<?xml version="1.0" encoding="UTF-8"?>
<!– Definition of new Model –>
<model name="zpe:zpeModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   <!– Optional meta-data about the model –>
   <description>ZPE Model</description>
   <version>1.0</version>
   <imports>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
      <import uri="http://www.alfresco.org/model/system/1.0" prefix="sys" />
   </imports>
   <namespaces>
      <namespace uri="http://www.domain.com/zpe/1.0" prefix="zpe"/>
   </namespaces>
   <types>
      <type name="zpe:zpeDocument">
         <title>ZPE document</title>
         <parent>cm:content</parent>
         <properties>
            <property name="zpe:centId">
               <type>d:long</type>
               <mandatory>true</mandatory>
            </property> 
            <property name="zpe:documentType">
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
            <property name="zpe:documentStatus">
               <type>d:text</type>
            </property>
            <!–
            Quite a few more
            –>
         </properties>
         <associations>
            <child-association name="zpe:documentLogs">
               <title>Comments</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>false</many>
               </source>
               <target>
                  <class>zpe:documentLog</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </child-association>
         </associations>
      </type>
      <type name="zpe:documentLog">
         <title>Document log</title>
         <parent>cm:content</parent>
         <properties>
            <property name="zpe:logText">
               <type>d:text</type>
               <index enabled="false" />
            </property>
            <property name="zpe:logUsername">
               <type>d:text</type>
               <index enabled="false" />
            </property>
            <property name="zpe:logDate">
               <type>d:datetime</type>
               <index enabled="false" />
            </property>
         </properties>
      </type>
   </types>
</model>
private String createCmisNode(final String folderIdString) {
   ObjectId folderId = new ObjectId() {
      @Override
      public String getId() {
         return folderIdString;
      }
   };
   Map<String, Object> properties = new HashMap<>();
   properties.put(PropertyIds.OBJECT_TYPE_ID, ZpeAlfType.ZPE_DOCUMENT_LOG.getTypeName());
   properties.put(PropertyIds.NAME, "zpeDocumentLogName");
   ContentStream contentStream = null;
   ObjectId objectNode = session.createDocument(properties, folderId, contentStream, VersioningState.NONE);
   return  objectNode.getId();
}
public void createZpeDocumentLog(final String cmisObjectId, Map<String, Object> properties, String documentType) throws IOException {
   // cmisObjectId = "workspace://SpacesStore/addb1495-90a4-4842-8bf0-b3b27de56410"
   OperationContext operationContext = session.createOperationContext();
   operationContext.setCacheEnabled(true);
   operationContext.setIncludeAcls(true);
   operationContext.setIncludePolicies(true);
   operationContext.setIncludeRelationships(IncludeRelationships.BOTH);
   session.setDefaultContext(operationContext);   
    CmisObject cmisObject = session.getObject(cmisObjectId);
   
   AlfrescoDocument tiffAlfDoc = (AlfrescoDocument) cmisObject;
   List<Folder> parents = tiffAlfDoc.getParents(operationContext); // TODO: takes several seconds!
   if (CollectionUtils.isEmpty(parents)) {
      throw new IOException("The given cmoObjectId has no parent folder");
   }
   Folder tiffFileParentFolder = parents.get(0);
   String propertyValue = tiffFileParentFolder.getPropertyValue(PropertyIds.OBJECT_ID);
   // create cmisObject of type "Node" to be able to add the documentLog there
   // later create a relation / association between the tif cmisObject and this node cmisObject
   final String cmisLogNodeObjectId = createCmisNode(propertyValue);
   
   // create relation:
   Document doc = (Document)session.getObject(new ObjectId() {
      @Override
      public String getId() {
         return cmisObjectId; // tiff image
      }
   });
   //Retrieve or create the log/logs
   CmisObject log = session.getObject(new ObjectId() {
      @Override
      public String getId() {
         return cmisLogNodeObjectId; // log document
      }
   });
   AlfrescoDocument alfDoc = (AlfrescoDocument) doc;
   alfDoc.addAspect("P:cm:referencesnode");
   Map<String, String> relProps = new HashMap<String, String>();
   relProps.put("cmis:sourceId", doc.getId());
   relProps.put("cmis:targetId", log.getId());
   relProps.put("cmis:objectTypeId", "zpe:documentLogs");
   session.createRelationship(relProps, null, null, null);
}
04-15-2013 04:11 AM
04-15-2013 04:41 AM
04-16-2013 03:24 AM
<?xml version="1.0" encoding="UTF-8"?>
<!– Definition of new Model –>
<model name="zpe:zpeModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   <!– Optional meta-data about the model –>
   <description>ZPE Model</description>
   <version>1.0</version>
   <imports>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
      <import uri="http://www.alfresco.org/model/system/1.0" prefix="sys" />
   </imports>
   <namespaces>
      <namespace uri="http://www.domain.com/zpe/1.0" prefix="zpe"/>
   </namespaces>
 
   <types>
      <type name="zpe:zpeDocument">
         <title>ZPE document</title>
         <parent>cm:content</parent>
         <properties>
            <property name="zpe:centId">
               <type>d:long</type>
               <mandatory>true</mandatory>
            </property> 
            <property name="zpe:documentType">
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
            <property name="zpe:documentStatus">
               <type>d:text</type>
            </property>
            <!–
            Quite a few more
            –>
         </properties>
         <associations>
            <child-association name="zpe:documentLogs">
               <title>Comments</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>false</many>
               </source>
               <target>
                  <class>zpe:documentLog</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </child-association>
         </associations>
      </type>
 
      <type name="zpe:documentLog">
         <title>Document log</title>
         <parent>cm:content</parent>
         <properties>
            <property name="zpe:logText">
               <type>d:text</type>
               <index enabled="false" />
            </property>
            <property name="zpe:logUsername">
               <type>d:text</type>
               <index enabled="false" />
            </property>
            <property name="zpe:logDate">
               <type>d:datetime</type>
               <index enabled="false" />
            </property>
         </properties>
      </type>
   </types>
   <aspects>
      <aspect name="zpe:docLoggable">
      <title>Document Log</title>
      <associations>
         <association name="zpe:docLogs">
            <source>
              <mandatory>false</mandatory>
              <many>false</many>
            </source>
            <target>
              <class>zpe:documentLog</class>
              <mandatory>false</mandatory>
              <many>true</many>
            </target>
         </association>
      </associations>
      </aspect>
   </aspects>
</model>
                Map<String, Object> properties = new HashMap<String, Object>();
      properties.put(PropertyIds.OBJECT_TYPE_ID, "D:zpe:zpeDocument");
      properties.put(PropertyIds.BASE_TYPE_ID, "zpe:zpeDocument");
      properties.put(PropertyIds.NAME,"doc"+System.currentTimeMillis());
      ContentStream cs = null;
      Document parentDoc = rootFolder.createDocument(properties, cs, VersioningState.NONE);
      
      Map<String, Object> childProperties = new HashMap<String, Object>();
      childProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:zpe:documentLog");
      childProperties.put(PropertyIds.NAME,"logdoc"+System.currentTimeMillis());
      Document childDoc = rootFolder.createDocument(childProperties, cs, VersioningState.NONE);
            
      Map<String, Object> relationProperties = new HashMap<String, Object>();
      relationProperties.put("cmis:sourceId", parentDoc.getId());
      relationProperties.put("cmis:targetId", childDoc.getId());
      relationProperties.put("cmis:objectTypeId", "R:zpe:docLogs");
      relationProperties.put("cmis:name","logid"+System.currentTimeMillis());
      session.createRelationship(relationProperties, null, null, null);
04-19-2013 07:58 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.