use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.
the class FreezeServiceImpl method hasFrozenChildren.
/**
* @see org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService#hasFrozenChildren(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public boolean hasFrozenChildren(final NodeRef nodeRef) {
ParameterCheck.mandatory("nodeRef", nodeRef);
boolean result = false;
// check that we are dealing with a record folder
if (isRecordFolder(nodeRef)) {
int heldCount = 0;
if (nodeService.hasAspect(nodeRef, ASPECT_HELD_CHILDREN)) {
heldCount = (Integer) getInternalNodeService().getProperty(nodeRef, PROP_HELD_CHILDREN_COUNT);
} else {
final TransactionService transactionService = (TransactionService) applicationContext.getBean("transactionService");
heldCount = AuthenticationUtil.runAsSystem(new RunAsWork<Integer>() {
@Override
public Integer doWork() {
return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Integer>() {
public Integer execute() throws Throwable {
int heldCount = 0;
// NOTE: this process remains to 'patch' older systems to improve performance next time around
List<ChildAssociationRef> childAssocs = getInternalNodeService().getChildAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, null);
if (childAssocs != null && !childAssocs.isEmpty()) {
for (ChildAssociationRef childAssociationRef : childAssocs) {
NodeRef record = childAssociationRef.getChildRef();
if (childAssociationRef.isPrimary() && isRecord(record) && isFrozen(record)) {
heldCount++;
}
}
}
// add aspect and set count
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(PROP_HELD_CHILDREN_COUNT, heldCount);
getInternalNodeService().addAspect(nodeRef, ASPECT_HELD_CHILDREN, props);
return heldCount;
}
}, false, true);
}
});
}
// true if more than one child held
result = (heldCount > 0);
}
return result;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.
the class JSONConversionComponent method setRmNodeValues.
/**
* Helper method to set the RM node values
*
* @param nodeRef node reference
* @param useShortQName indicates whether the short QName are used or not
* @return {@link JSONObject} JSON object containing values
*/
@SuppressWarnings("unchecked")
private JSONObject setRmNodeValues(final NodeRef nodeRef, final boolean useShortQName) {
JSONObject rmNodeValues = new JSONObject();
// UI convenience type
rmNodeValues.put("uiType", getUIType(nodeRef));
// Get the 'kind' of the file plan component
FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(nodeRef);
rmNodeValues.put("kind", kind.toString());
// set the primary parent node reference
ChildAssociationRef assoc = nodeService.getPrimaryParent(nodeRef);
if (assoc != null) {
rmNodeValues.put("primaryParentNodeRef", assoc.getParentRef().toString());
}
Map<String, Object> values = AuthenticationUtil.runAsSystem(new RunAsWork<Map<String, Object>>() {
public Map<String, Object> doWork() throws Exception {
Map<String, Object> result = new HashMap<String, Object>();
// File plan node reference
NodeRef filePlan = filePlanService.getFilePlan(nodeRef);
if (filePlan != null) {
result.put("filePlan", filePlan.toString());
// Unfiled container node reference
NodeRef unfiledRecordContainer = filePlanService.getUnfiledContainer(filePlan);
if (unfiledRecordContainer != null) {
result.put("unfiledRecordContainer", unfiledRecordContainer.toString());
result.put("properties", propertiesToJSON(unfiledRecordContainer, nodeService.getProperties(unfiledRecordContainer), useShortQName));
QName type = fileFolderService.getFileInfo(unfiledRecordContainer).getType();
result.put("type", useShortQName ? type.toPrefixString(namespaceService) : type.toString());
}
}
return result;
}
});
rmNodeValues.putAll(values);
// Set the indicators array
setIndicators(rmNodeValues, nodeRef);
// Set the actions array
setActions(rmNodeValues, nodeRef);
return rmNodeValues;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.
the class SplitEmailAction method createAttachment.
/**
* Create attachment from Mime Message Part
* @param messageNodeRef - the node ref of the mime message
* @param parentNodeRef - the node ref of the parent folder
* @param part
* @throws MessagingException
* @throws IOException
*/
private void createAttachment(NodeRef messageNodeRef, NodeRef parentNodeRef, Part part) throws MessagingException, IOException {
String fileName = part.getFileName();
try {
fileName = MimeUtility.decodeText(fileName);
} catch (UnsupportedEncodingException e) {
if (logger.isWarnEnabled()) {
logger.warn("Cannot decode file name '" + fileName + "'", e);
}
}
Map<QName, Serializable> messageProperties = getNodeService().getProperties(messageNodeRef);
String messageTitle = (String) messageProperties.get(ContentModel.PROP_NAME);
if (messageTitle == null) {
messageTitle = fileName;
} else {
messageTitle = messageTitle + " - " + fileName;
}
ContentType contentType = new ContentType(part.getContentType());
Map<QName, Serializable> docProps = new HashMap<QName, Serializable>(1);
docProps.put(ContentModel.PROP_NAME, messageTitle + " - " + fileName);
docProps.put(ContentModel.PROP_TITLE, fileName);
/**
* Create an attachment node in the same folder as the message
*/
ChildAssociationRef attachmentRef = getNodeService().createNode(parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, fileName), ContentModel.TYPE_CONTENT, docProps);
/**
* Write the content into the new attachment node
*/
ContentWriter writer = getContentService().getWriter(attachmentRef.getChildRef(), ContentModel.PROP_CONTENT, true);
writer.setMimetype(contentType.getBaseType());
OutputStream os = writer.getContentOutputStream();
FileCopyUtils.copy(part.getInputStream(), os);
/**
* Create a link from the message to the attachment
*/
createRMReference(messageNodeRef, attachmentRef.getChildRef());
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.
the class RecordsManagementSearchServiceImpl method search.
/**
* @see org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService#search(java.lang.String, java.lang.String, org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchParameters)
*/
@Override
public List<Pair<NodeRef, NodeRef>> search(String siteId, String query, RecordsManagementSearchParameters rmSearchParameters) {
// build the full RM query
StringBuilder fullQuery = new StringBuilder(1024);
fullQuery.append("PATH:\"").append(SITES_SPACE_QNAME_PATH).append("cm:").append(ISO9075.encode(siteId)).append("/cm:documentLibrary//*\"").append(" AND (").append(buildQueryString(query, rmSearchParameters)).append(")");
// create the search parameters
SearchParameters searchParameters = new SearchParameters();
searchParameters.setQuery(fullQuery.toString());
searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
searchParameters.setMaxItems(rmSearchParameters.getMaxItems());
searchParameters.setNamespace(RecordsManagementModel.RM_URI);
// set sort
for (SortItem entry : rmSearchParameters.getSortOrder()) {
searchParameters.addSort(entry.property.toPrefixString(namespaceService), entry.assc);
}
// set templates
for (Entry<String, String> entry : rmSearchParameters.getTemplates().entrySet()) {
searchParameters.addQueryTemplate(entry.getKey(), entry.getValue());
}
// execute query
ResultSet resultSet = searchService.query(searchParameters);
// process results
List<Pair<NodeRef, NodeRef>> result = new ArrayList<Pair<NodeRef, NodeRef>>(resultSet.length());
for (ChildAssociationRef childAssoc : resultSet.getChildAssocRefs()) {
result.add(new Pair<NodeRef, NodeRef>(childAssoc.getParentRef(), childAssoc.getChildRef()));
}
// return results
return result;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.
the class ExtendedSecurityServiceImpl method set.
/**
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#set(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set)
*/
@Override
public void set(NodeRef nodeRef, Set<String> readers, Set<String> writers) {
ParameterCheck.mandatory("nodeRef", nodeRef);
// remove existing extended security, assuming there is any
remove(nodeRef);
// find groups
Pair<String, String> iprGroups = createOrFindIPRGroups(readers, writers);
// assign groups to correct fileplan roles
NodeRef filePlan = filePlanService.getFilePlan(nodeRef);
filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_EXTENDED_READERS, iprGroups.getFirst());
filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_EXTENDED_WRITERS, iprGroups.getSecond());
// assign groups to node
assignIPRGroupsToNode(iprGroups, nodeRef);
// apply the readers to any renditions of the content
if (isRecord(nodeRef)) {
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(nodeRef, RenditionModel.ASSOC_RENDITION, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef assoc : assocs) {
NodeRef child = assoc.getChildRef();
assignIPRGroupsToNode(iprGroups, child);
}
}
}
Aggregations