use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class WorkingCopyAspect method beforeArchiveNode.
/**
* beforeArchiveNode policy behaviour
*
* @param nodeRef
* the node reference about to be archived
*/
@Override
public void beforeArchiveNode(NodeRef workingCopyNodeRef) {
NodeRef checkedOutNodeRef = checkOutCheckInService.getCheckedOut(workingCopyNodeRef);
if (checkedOutNodeRef != null) {
try {
policyBehaviourFilter.disableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_AUDITABLE);
if (nodeService.hasAspect(checkedOutNodeRef, ContentModel.ASPECT_LOCKABLE)) {
Map<QName, Serializable> checkedOutNodeProperties = nodeService.getProperties(checkedOutNodeRef);
Map<QName, Serializable> workingCopyProperties = nodeService.getProperties(workingCopyNodeRef);
Long nodeId = nodeDAO.getNodePair(workingCopyNodeRef).getFirst();
// get lock properties from checked out node and set them on working copy node in order to be available for restore
String lockOwner = (String) checkedOutNodeProperties.get(ContentModel.PROP_LOCK_OWNER);
Date expiryDate = (Date) checkedOutNodeProperties.get(ContentModel.PROP_EXPIRY_DATE);
String lockTypeStr = (String) checkedOutNodeProperties.get(ContentModel.PROP_LOCK_TYPE);
LockType lockType = lockTypeStr != null ? LockType.valueOf(lockTypeStr) : null;
String lifetimeStr = (String) checkedOutNodeProperties.get(ContentModel.PROP_LOCK_LIFETIME);
Lifetime lifetime = lifetimeStr != null ? Lifetime.valueOf(lifetimeStr) : null;
String additionalInfo = (String) checkedOutNodeProperties.get(ContentModel.PROP_LOCK_ADDITIONAL_INFO);
nodeService.addAspect(workingCopyNodeRef, ContentModel.ASPECT_ARCHIVE_LOCKABLE, null);
workingCopyProperties.put(ContentModel.PROP_ARCHIVED_LOCK_OWNER, lockOwner);
workingCopyProperties.put(ContentModel.PROP_ARCHIVED_LOCK_TYPE, lockType);
workingCopyProperties.put(ContentModel.PROP_ARCHIVED_LOCK_LIFETIME, lifetime);
workingCopyProperties.put(ContentModel.PROP_ARCHIVED_EXPIRY_DATE, expiryDate);
workingCopyProperties.put(ContentModel.PROP_ARCHIVED_LOCK_ADDITIONAL_INFO, additionalInfo);
// Target associations
Collection<Pair<Long, AssociationRef>> targetAssocs = nodeDAO.getTargetNodeAssocs(nodeId, null);
for (Pair<Long, AssociationRef> targetAssocPair : targetAssocs) {
if (ContentModel.ASSOC_ORIGINAL.equals(targetAssocPair.getSecond().getTypeQName())) {
workingCopyProperties.put(ContentModel.PROP_ARCHIVED_TARGET_ASSOCS, targetAssocPair.getSecond());
}
}
// Source associations
Collection<Pair<Long, AssociationRef>> sourceAssocs = nodeDAO.getSourceNodeAssocs(nodeId, null);
for (Pair<Long, AssociationRef> sourceAssocPair : sourceAssocs) {
if (ContentModel.ASSOC_WORKING_COPY_LINK.equals(sourceAssocPair.getSecond().getTypeQName())) {
workingCopyProperties.put(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS, sourceAssocPair.getSecond());
}
}
// update working copy node properties
nodeService.setProperties(workingCopyNodeRef, workingCopyProperties);
}
} finally {
policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
}
}
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class PolicyFactory method convertMTArgs.
/**
* Convert each of the arguments to the spoofed (no tenant prefix) reference.
*
* Converts arguments of Type NodeRef to base name etc.
*
* @param args list of non final arguments - the arguments are updated in place
*/
protected static void convertMTArgs(Object[] args) {
// Convert each of the arguments to the spoofed (no tenant prefix) reference
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
Object newArg = arg;
if (arg == null) {
// No conversion possible
}
if (arg instanceof StoreRef) {
StoreRef ref = (StoreRef) arg;
newArg = tenantService.getBaseName(ref);
} else if (arg instanceof NodeRef) {
NodeRef ref = (NodeRef) arg;
newArg = tenantService.getBaseName(ref);
} else if (arg instanceof ChildAssociationRef) {
ChildAssociationRef ref = (ChildAssociationRef) arg;
newArg = tenantService.getBaseName(ref);
} else if (arg instanceof AssociationRef) {
AssociationRef ref = (AssociationRef) arg;
newArg = tenantService.getBaseName(ref);
}
// Substitute the new value
args[i] = newArg;
}
}
use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.
the class DocumentPropertiesDialog method save.
/**
* Event handler used to save the edited properties back to the repository
*
* @return The outcome
*/
public String save() {
String outcome = "cancel";
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin();
NodeRef nodeRef = this.browseBean.getDocument().getNodeRef();
Map<String, Object> props = this.editableNode.getProperties();
// get the name and move the node as necessary
String name = (String) props.get(ContentModel.PROP_NAME);
if (name != null) {
getFileFolderService().rename(nodeRef, name);
}
Map<QName, Serializable> properties = getNodeService().getProperties(nodeRef);
// we need to put all the properties from the editable bag back into
// the format expected by the repository
// Deal with the special mimetype property for ContentData
String mimetype = (String) props.get(TEMP_PROP_MIMETYPE);
if (mimetype != null) {
// remove temporary prop from list so it isn't saved with the others
props.remove(TEMP_PROP_MIMETYPE);
ContentData contentData = (ContentData) props.get(ContentModel.PROP_CONTENT);
if (contentData != null) {
contentData = ContentData.setMimetype(contentData, mimetype);
props.put(ContentModel.PROP_CONTENT.toString(), contentData);
}
}
// Deal with the special encoding property for ContentData
String encoding = (String) props.get(TEMP_PROP_ENCODING);
if (encoding != null) {
// remove temporary prop from list so it isn't saved with the others
props.remove(TEMP_PROP_ENCODING);
ContentData contentData = (ContentData) props.get(ContentModel.PROP_CONTENT);
if (contentData != null) {
contentData = ContentData.setEncoding(contentData, encoding);
props.put(ContentModel.PROP_CONTENT.toString(), contentData);
}
}
// extra and deal with the Author prop if the aspect has not been applied yet
String author = (String) props.get(ContentModel.PROP_AUTHOR);
if (author != null && author.length() != 0) {
// add aspect if required
if (getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_AUTHOR) == false) {
Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
authorProps.put(ContentModel.PROP_AUTHOR, author);
getNodeService().addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
}
// else it will get updated in the later setProperties() call
}
// deal with adding the "titled" aspect if required
String title = (String) props.get(ContentModel.PROP_TITLE);
String description = (String) props.get(ContentModel.PROP_DESCRIPTION);
if (title != null || description != null) {
// add the aspect to be sure it's present
getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
// props will get added later in setProperties()
}
// add the remaining properties
Iterator<String> iterProps = props.keySet().iterator();
while (iterProps.hasNext()) {
String propName = iterProps.next();
QName qname = QName.createQName(propName);
// make sure the property is represented correctly
Serializable propValue = (Serializable) props.get(propName);
// check for empty strings when using number types, set to null in this case
if ((propValue != null) && (propValue instanceof String) && (propValue.toString().length() == 0)) {
PropertyDefinition propDef = getDictionaryService().getProperty(qname);
if (propDef != null) {
if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || propDef.getDataType().getName().equals(DataTypeDefinition.INT) || propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
propValue = null;
}
}
}
properties.put(qname, propValue);
}
// send the properties back to the repository
getNodeService().setProperties(this.browseBean.getDocument().getNodeRef(), properties);
// we also need to persist any association changes that may have been made
// add any associations added in the UI
Map<String, Map<String, AssociationRef>> addedAssocs = this.editableNode.getAddedAssociations();
for (Map<String, AssociationRef> typedAssoc : addedAssocs.values()) {
for (AssociationRef assoc : typedAssoc.values()) {
getNodeService().createAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
}
}
// remove any association removed in the UI
Map<String, Map<String, AssociationRef>> removedAssocs = this.editableNode.getRemovedAssociations();
for (Map<String, AssociationRef> typedAssoc : removedAssocs.values()) {
for (AssociationRef assoc : typedAssoc.values()) {
getNodeService().removeAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
}
}
// add any child associations added in the UI
Map<String, Map<String, ChildAssociationRef>> addedChildAssocs = this.editableNode.getAddedChildAssociations();
for (Map<String, ChildAssociationRef> typedAssoc : addedChildAssocs.values()) {
for (ChildAssociationRef assoc : typedAssoc.values()) {
getNodeService().addChild(assoc.getParentRef(), assoc.getChildRef(), assoc.getTypeQName(), assoc.getTypeQName());
}
}
// remove any child association removed in the UI
Map<String, Map<String, ChildAssociationRef>> removedChildAssocs = this.editableNode.getRemovedChildAssociations();
for (Map<String, ChildAssociationRef> typedAssoc : removedChildAssocs.values()) {
for (ChildAssociationRef assoc : typedAssoc.values()) {
getNodeService().removeChild(assoc.getParentRef(), assoc.getChildRef());
}
}
// commit the transaction
tx.commit();
// set the outcome to refresh
outcome = "finish";
// reset the document held by the browse bean as it's just been updated
this.browseBean.getDocument().reset();
} catch (FileExistsException e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
// print status message
String statusMsg = MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), "error_exists"), e.getName());
Utils.addErrorMessage(statusMsg);
// no outcome
outcome = null;
} catch (InvalidNodeRefException err) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() }));
// this failure means the node no longer exists - we cannot show the doc properties screen
outcome = "browse";
} catch (Throwable e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
}
return outcome;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.
the class AdminNodeBrowseBean method selectFromNode.
/**
* Action to select association From node
*
* @return next action
*/
public String selectFromNode() {
AssociationRef assocRef = (AssociationRef) getSourceAssocs().getRowData();
NodeRef sourceRef = assocRef.getSourceRef();
setNodeRef(sourceRef);
return "success";
}
use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.
the class UIAssociationEditor method removeTarget.
/**
* Updates the component and node state to reflect an association being removed
*
* @param node The node we are dealing with
* @param targetRef The noderef of the child to remove
*/
protected void removeTarget(Node node, String targetRef) {
if (node != null && targetRef != null) {
QName assocQName = Repository.resolveToQName(this.associationName);
AssociationRef newAssoc = new AssociationRef(null, node.getNodeRef(), assocQName, new NodeRef(targetRef));
// was one of the original ones
if (this.originalAssocs.containsKey(targetRef)) {
Map<String, AssociationRef> removed = node.getRemovedAssociations().get(this.associationName);
removed.put(targetRef, newAssoc);
if (logger.isDebugEnabled())
logger.debug("Added association to " + targetRef + " to the removed list");
}
// if this association was previously added in this session it will still be
// in the added list so remove it if it is
Map<String, AssociationRef> added = node.getAddedAssociations().get(this.associationName);
if (added.containsKey(targetRef)) {
added.remove(targetRef);
if (logger.isDebugEnabled())
logger.debug("Removed association to " + targetRef + " from the added list");
}
}
}
Aggregations