Java API
ORM API
beCPG provides an Alfresco model to Java POJO mapping to manipulate beCPG entities.
It maps Java POJOs to Alfresco data models, so you can use the Java API to manipulate these objects. The mapping is based on Java 5 annotations.
A set of annotations represents Alfresco properties or associations:
@AlfQname --> Specify the alfresco qName
@AlfType --> Match to an alfresco type
@AlfProp --> Match to an alfresco properties
@AlfMlText --> Match a special mltext property
@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
A special set of annotations represents beCPG datalists (not covered in detail here):
@DataList
@DataListIdentifierAttr
@DataListView
@MultiLevelDataList
Let's say you want to create and manipulate objects of the deliverable type.
First, create your Alfresco model:
<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 must extend BeCPGDataObject. Setters, hashCode, equals and toString are not shown but are mandatory.
Then use the AlfrescoRepository class to perform CRUD operations on your new POJO:
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 a utility class to build safe and fast FTS or Alfresco Lucene queries. This class builds transactional queries whenever possible. See https://docs.hyland.com/r/Alfresco/Alfresco-Search-Services/2.0/Alfresco-Search-Services 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();