use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class BehaviourFilterImpl method enableBehaviour.
@Override
@Extend(traitAPI = BehaviourFilterTrait.class, extensionAPI = BehaviourFilterExtension.class)
public void enableBehaviour(NodeRef nodeRef, QName className) {
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("className", className);
if (logger.isDebugEnabled()) {
logger.debug("Behaviour: ENABLE (" + AlfrescoTransactionSupport.getTransactionId() + "): " + nodeRef + "/" + className);
}
TransactionalResourceHelper.decrementCount(KEY_FILTER_COUNT, false);
if (!TransactionalResourceHelper.isResourcePresent(KEY_INSTANCE_CLASS_FILTERS)) {
// Nothing was disabled
return;
}
nodeRef = tenantService.getName(nodeRef);
Map<NodeRef, Map<QName, MutableInt>> instanceClassFilters = TransactionalResourceHelper.getMap(KEY_INSTANCE_CLASS_FILTERS);
Map<QName, MutableInt> classFilters = instanceClassFilters.get(nodeRef);
if (classFilters == null) {
// Instance classes were not disabled
return;
}
MutableInt filter = classFilters.get(className);
if (filter == null) {
// Class was not disabled
return;
} else if (filter.intValue() <= 0) {
// Can't go below zero for this
} else {
filter.decrement();
}
if (logger.isDebugEnabled()) {
logger.debug(" Now: " + filter);
}
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class WorkflowPackageImpl method setWorkflowForPackage.
/**
* {@inheritDoc}
*/
@Extend(traitAPI = WorkflowPackageTrait.class, extensionAPI = WorkflowPackageExtension.class)
public boolean setWorkflowForPackage(WorkflowInstance instance) {
NodeRef packageNode = instance.getWorkflowPackage();
if (packageNode == null)
return false;
Serializable pckgInstanceId = nodeService.getProperty(packageNode, WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
if (pckgInstanceId != null) {
if (pckgInstanceId.equals(instance.getId())) {
return false;
}
String msg = messageService.getMessage(ERR_PACKAGE_ALREADY_ASSOCIATED, packageNode, instance.getId(), pckgInstanceId);
throw new WorkflowException(msg);
}
if (nodeService.hasAspect(packageNode, WorkflowModel.ASPECT_WORKFLOW_PACKAGE) == false) {
createPackage(packageNode);
}
String definitionId = instance.getDefinition().getId();
String definitionName = instance.getDefinition().getName();
String instanceId = instance.getId();
nodeService.setProperty(packageNode, WorkflowModel.PROP_WORKFLOW_DEFINITION_ID, definitionId);
nodeService.setProperty(packageNode, WorkflowModel.PROP_WORKFLOW_DEFINITION_NAME, definitionName);
nodeService.setProperty(packageNode, WorkflowModel.PROP_WORKFLOW_INSTANCE_ID, instanceId);
return true;
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class CheckOutCheckInServiceImpl method checkout.
@Override
@Extend(traitAPI = CheckOutCheckInServiceTrait.class, extensionAPI = CheckOutCheckInServiceExtension.class)
public NodeRef checkout(final NodeRef nodeRef, final NodeRef destinationParentNodeRef, final QName destinationAssocTypeQName, QName destinationAssocQName) {
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT)) {
throw new CheckOutCheckInServiceException(MSG_ALREADY_CHECKEDOUT);
}
// Make sure we are not checking out a working copy node
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
throw new CheckOutCheckInServiceException(MSG_ERR_ALREADY_WORKING_COPY);
}
// It is not enough to check LockUtils.isLockedOrReadOnly in case when the same user does offline and online edit (for instance in two open browsers). In this case we get
// set ContentModel.ASPECT_LOCKABLE and LockType.WRITE_LOCK. So, here we have to check following
LockStatus lockStatus = lockService.getLockStatus(nodeRef);
if (lockStatus != LockStatus.NO_LOCK && lockStatus != LockStatus.LOCK_EXPIRED) {
throw new NodeLockedException(nodeRef);
}
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableBehaviour(destinationParentNodeRef, ContentModel.ASPECT_AUDITABLE);
try {
return doCheckout(nodeRef, destinationParentNodeRef, destinationAssocTypeQName, destinationAssocQName);
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableBehaviour(destinationParentNodeRef, ContentModel.ASPECT_AUDITABLE);
}
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class CheckOutCheckInServiceImpl method cancelCheckout.
@Override
@Extend(traitAPI = CheckOutCheckInServiceTrait.class, extensionAPI = CheckOutCheckInServiceExtension.class)
public NodeRef cancelCheckout(NodeRef workingCopyNodeRef) {
// Check that we have been handed a working copy
if (!nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY)) {
// Error since we have not been passed a working copy
throw new AspectMissingException(ContentModel.ASPECT_WORKING_COPY, workingCopyNodeRef);
}
// Get the checked out node
NodeRef nodeRef = getCheckedOut(workingCopyNodeRef);
if (nodeRef == null) {
// Error since the original node can not be found
throw new CheckOutCheckInServiceException(MSG_ERR_BAD_COPY);
}
// Invoke policy
invokeBeforeCancelCheckOut(workingCopyNodeRef);
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY);
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT);
try {
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE)) {
// Release the lock on the original node
lockService.unlock(nodeRef, false, true);
}
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT);
// Delete the working copy
nodeService.deleteNode(workingCopyNodeRef);
// Invoke policy
invokeOnCancelCheckOut(nodeRef);
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT)) {
nodeService.deleteNode(nodeRef);
}
} catch (UnableToReleaseLockException exception) {
throw new CheckOutCheckInServiceException(MSG_ERR_NOT_OWNER, exception);
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT);
}
return nodeRef;
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class CheckOutCheckInServiceImpl method checkin.
@Override
@Extend(traitAPI = CheckOutCheckInServiceTrait.class, extensionAPI = CheckOutCheckInServiceExtension.class)
public NodeRef checkin(NodeRef workingCopyNodeRef, Map<String, Serializable> versionProperties, String contentUrl, boolean keepCheckedOut) {
// Check that we have been handed a working copy
if (!nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY)) {
// Error since we have not been passed a working copy
throw new AspectMissingException(ContentModel.ASPECT_WORKING_COPY, workingCopyNodeRef);
}
// Get the checked out node
NodeRef nodeRef = getCheckedOut(workingCopyNodeRef);
if (nodeRef == null) {
// Error since the original node can not be found
throw new CheckOutCheckInServiceException(MSG_ERR_BAD_COPY);
}
// Invoke policy
invokeBeforeCheckIn(workingCopyNodeRef, versionProperties, contentUrl, keepCheckedOut);
try {
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE)) {
// Release the lock on the original node
lockService.unlock(nodeRef, false, true);
}
} catch (UnableToReleaseLockException exception) {
throw new CheckOutCheckInServiceException(MSG_ERR_NOT_OWNER, exception);
}
if (contentUrl != null) {
ContentData contentData = (ContentData) nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_CONTENT);
if (contentData == null) {
throw new AlfrescoRuntimeException(MSG_ERR_WORKINGCOPY_HAS_NO_CONTENT, new Object[] { workingCopyNodeRef });
} else {
contentData = new ContentData(contentUrl, contentData.getMimetype(), contentData.getSize(), contentData.getEncoding());
}
// Set the content url value onto the working copy
nodeService.setProperty(workingCopyNodeRef, ContentModel.PROP_CONTENT, contentData);
}
// Copy the contents of the working copy onto the original
this.copyService.copy(workingCopyNodeRef, nodeRef);
// Handle name change on working copy (only for folders/files)
if (fileFolderService.getFileInfo(workingCopyNodeRef) != null) {
String origName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
String name = (String) nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_NAME);
String wcLabel = (String) this.nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_WORKING_COPY_LABEL);
if (wcLabel == null) {
wcLabel = getWorkingCopyLabel();
}
if (hasWorkingCopyNameChanged(name, origName, wcLabel)) {
// ensure working copy has working copy label in its name to avoid name clash
if (!name.contains(" " + wcLabel)) {
try {
fileFolderService.rename(workingCopyNodeRef, createWorkingCopyName(name, wcLabel));
} catch (FileExistsException e) {
throw new CheckOutCheckInServiceException(e, MSG_ERR_CANNOT_RENAME, name, wcLabel);
} catch (FileNotFoundException e) {
throw new CheckOutCheckInServiceException(e, MSG_ERR_CANNOT_RENAME, name, wcLabel);
}
}
String newName = getNameFromWorkingCopyName(name, wcLabel);
try {
// rename original to changed working name
fileFolderService.rename(nodeRef, newName);
} catch (FileExistsException e) {
throw new CheckOutCheckInServiceException(e, MSG_ERR_CANNOT_RENAME, origName, newName);
} catch (FileNotFoundException e) {
throw new CheckOutCheckInServiceException(e, MSG_ERR_CANNOT_RENAME, name, newName);
}
}
}
if (versionProperties != null && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) && !nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT)) {
// Create the new version
this.versionService.createVersion(nodeRef, versionProperties);
}
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT);
if (keepCheckedOut == false) {
// Delete the working copy
// Disable cm:auditable aspect
// See MNT-8789
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY);
try {
// Clean up original node
// Note: Lock has already been removed. So no lockService.unlock(nodeRef);
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT);
// Delete the working copy
nodeService.deleteNode(workingCopyNodeRef);
} finally {
// Just for symmetry; the node is gone
behaviourFilter.enableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY);
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
}
} else {
// Re-lock the original node
lockService.lock(nodeRef, LockType.READ_ONLY_LOCK);
}
// Invoke policy
invokeOnCheckIn(nodeRef);
return nodeRef;
}
Aggregations