Java API

ORM API

beCPG provides a powerful Alfresco Model to Java Pojo Mapping for manipulating beCPG entity.

It allows to map Java Pojo with Alfresco data models and use java api to manipulate these objects.\ The mapping is based on Java 5 annotations.

There is a set of annotation that represents alfresco properties or associations

@AlfQname --> Specify the alfresco qName 
@AlfType --> Match to an alfresco type
@AlfProp --> Match to an alfresco properties
@AlfMlText -->  Math a special mltext properties

@AlfSingleAssoc --> Match to a single target association
@AlfMultiAssoc --> Match to a multiple target association
@AlfEnforced --> Save field even if null 
@AlfReadOnly --> Doesn't save the property

And a special set of annotations that represent beCPG datalists (will not be covered in details)

@DataList
@DataListIdentifierAttr
@DataListView
@MultiLevelDataList

Let's says you want to create and manipulate deliverable types objects.

First create your alfresco models :

            <type name="pjt:deliverable">
                <properties>
                    <property name="pjt:dlDescription">
                        <type>d:text</type>
                        <mandatory>true</mandatory>
                    </property>
                    <property name="pjt:dlState">
                        <type>d:text</type>
                        <constraints>
                            <constraint ref="pjt:deliverableStates" />
                        </constraints>
                    </property>
                    <property name="pjt:dlUrl">
                        <type>d:text</type>
                    </property>
                </properties>
                <associations>
                    <association name="pjt:dlTask">
                        <source>
                            <mandatory>true</mandatory>
                            <many>true</many>
                        </source>
                        <target>
                            <class>pjt:taskList</class>
                            <mandatory>true</mandatory>
                            <many>false</many>
                        </target>
                    </association>
                    <association name="pjt:dlContent">
                        <source>
                            <mandatory>false</mandatory>
                            <many>true</many>
                        </source>
                        <target>
                            <class>cm:content</class>
                            <mandatory>false</mandatory>
                            <many>false</many>
                        </target>
                    </association>
                </associations>
            </type>

Then create the corresponding Java Object with beCPG annotations

    @AlfType
    @AlfQname(qname = "pjt:deliverable")
    public class Deliverable extends BeCPGDataObject {

        private NodeRef task;
        private DeliverableState state = DeliverableState.Planned;
        private String description;
        private String url;
        private Integer completionPercent = 0;
        private NodeRef content;

        @AlfSingleAssoc
        @AlfQname(qname = "pjt:dlTask")
        public NodeRef getTask() {
            return task;
        }

        @AlfProp
            @AlfQname(qname = "pjt:dlUrl")
        public String getUrl() {
            return url;
         }

        @AlfProp
        @AlfQname(qname = "pjt:dlState")
         public DeliverableState getState() {
            return state;
         }


        @AlfProp
        @AlfQname(qname = "pjt:dlDescription")
        public String getDescription() {
            return description;
        }

        @AlfProp
        @AlfQname(qname = "pjt:completionPercent")
        public Integer getCompletionPercent() {
            return completionPercent;
        }

        @AlfSingleAssoc
        @AlfQname(qname = "pjt:dlContent")
        public NodeRef getContent() {
            return content;
        }
       ...
    }

Your class should implement BeCPGDataObject. Setters, hashCode, equals and toString are not represented but mandatory.

Then use AlfrescoRepository class to CRUD your new POJO. That's it.

    public class TestORM {
     @Resource
     protected AlfrescoRepository<Deliverable> alfrescoRepository;
     @Test
     public void test() {
            //CRUD
            Deliverable deliverable = new Deliverable();            
            deliverable.setParentNodeRef(getParentNodeRef());

            //Create
            alfrescoRepository.save(deliverable);            
            NodeRef deliverableNodeRef = deliverable.getNodeRef();

            //Retrieve
            deliverable = alfrescoRepository.findOne(deliverableNodeRef);            
            deliverable.setDescription("Test");
            //Update
            alfrescoRepository.save(deliverable);        }
       ...
    }

Search query builder

beCPG provides an utility class to build safe and fast FTS or Alfresco Lucene query. This class will try as much as possible to build transactionnal query. See https://docs.alfresco.com/search-services/latest/config/transactional/ for more information

Here are some use cases :

    //Getting some search results
    List<NodeRef> ret = BeCPGQueryBuilder.createQuery()
                    .ofType(ContentModel.TYPE_FOLDER)
                    .isNotNull(ContentModel.PROP_MODIFIED)
                    .excludeAspect(ContentModel.ASPECT_WORKING_COPY)
                    .withAspect(ContentModel.ASPECT_TITLED)
                    .addSort(ContentModel.PROP_MODIFIED,true).list();

    // Getting unlimited results, it will do an internal pagination based on date modified 
    List<NodeRef> ret = BeCPGQueryBuilder.createQuery()
                    .ofType(ContentModel.TYPE_FOLDER).maxResults(RepoConsts.MAX_RESULTS_UNLIMITED).list();

    //Getting single result or null
    NodeRef nodeRef  = BeCPGQueryBuilder.createQuery()
                    .ofType(ContentModel.TYPE_FOLDER)
                    .andPropEquals(ContentModel.PROP_NAME, "Test").singleValue();

results matching ""

    No results matching ""