use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.
the class EditSpaceDialog method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
// update the existing node in the repository
NodeRef nodeRef = this.editableNode.getNodeRef();
Map<String, Object> editedProps = this.editableNode.getProperties();
// handle the name property separately, perform a rename in case it changed
String name = (String) editedProps.get(ContentModel.PROP_NAME);
if (name != null) {
this.getFileFolderService().rename(nodeRef, name);
}
// build the properties to add to the repository
Map<QName, Serializable> repoProps = new HashMap<QName, Serializable>(7);
// overwrite the current properties with the edited ones
Iterator<String> iterProps = editedProps.keySet().iterator();
while (iterProps.hasNext()) {
String propName = iterProps.next();
QName qname = QName.createQName(propName);
// make sure the property is represented correctly
Serializable propValue = (Serializable) editedProps.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 = this.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;
}
}
}
repoProps.put(qname, propValue);
}
// add the new properties back to the repository
this.getNodeService().addProperties(nodeRef, repoProps);
// 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()) {
this.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()) {
this.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()) {
this.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()) {
this.getNodeService().removeChild(assoc.getParentRef(), assoc.getChildRef());
}
}
// do nothing by default, subclasses can override if necessary
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.
the class UsersBeanProperties method getAvatarUrl.
public String getAvatarUrl() {
String avatarUrl = null;
List<AssociationRef> refs = getNodeService().getTargetAssocs(this.person.getNodeRef(), ContentModel.ASSOC_AVATAR);
if (refs.size() == 1) {
NodeRef photoRef = refs.get(0).getTargetRef();
String name = (String) getNodeService().getProperty(photoRef, ContentModel.PROP_NAME);
avatarUrl = DownloadContentServlet.generateBrowserURL(photoRef, name);
}
return avatarUrl;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.
the class EditContentPropertiesDialog method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
NodeRef nodeRef = this.editableNode.getNodeRef();
Map<String, Object> editedProps = this.editableNode.getProperties();
// get the name and move the node as necessary
String name = (String) editedProps.get(ContentModel.PROP_NAME);
if (name != null) {
getFileFolderService().rename(nodeRef, name);
}
// we need to put all the properties from the editable bag back into
// the format expected by the repository
Map<QName, Serializable> repoProps = this.getNodeService().getProperties(nodeRef);
// Extract and deal with the special mimetype property for ContentData
String mimetype = (String) editedProps.get(TEMP_PROP_MIMETYPE);
if (mimetype != null) {
// remove temporary prop from list so it isn't saved with the others
editedProps.remove(TEMP_PROP_MIMETYPE);
ContentData contentData = (ContentData) editedProps.get(ContentModel.PROP_CONTENT);
if (contentData != null) {
contentData = ContentData.setMimetype(contentData, mimetype);
editedProps.put(ContentModel.PROP_CONTENT.toString(), contentData);
}
}
// Extract and deal with the special encoding property for ContentData
String encoding = (String) editedProps.get(TEMP_PROP_ENCODING);
if (encoding != null) {
// remove temporary prop from list so it isn't saved with the others
editedProps.remove(TEMP_PROP_ENCODING);
ContentData contentData = (ContentData) editedProps.get(ContentModel.PROP_CONTENT);
if (contentData != null) {
contentData = ContentData.setEncoding(contentData, encoding);
editedProps.put(ContentModel.PROP_CONTENT.toString(), contentData);
}
}
// add the "author" aspect if required, properties will get set below
if (this.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_AUTHOR) == false) {
this.getNodeService().addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, null);
}
// add the "titled" aspect if required, properties will get set below
if (this.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false) {
getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
}
// add the remaining properties
Iterator<String> iterProps = editedProps.keySet().iterator();
while (iterProps.hasNext()) {
String propName = iterProps.next();
QName qname = QName.createQName(propName);
// make sure the property is represented correctly
Serializable propValue = (Serializable) editedProps.get(propName);
// check for empty strings when using number types, set to null in this case
if (propValue instanceof String) {
PropertyDefinition propDef = this.getDictionaryService().getProperty(qname);
if (((String) propValue).length() == 0) {
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;
}
}
} else // handle locale strings to Locale objects
if (propDef != null && propDef.getDataType().getName().equals(DataTypeDefinition.LOCALE)) {
propValue = I18NUtil.parseLocale((String) propValue);
}
}
repoProps.put(qname, propValue);
}
// send the properties back to the repository
this.getNodeService().setProperties(nodeRef, repoProps);
// 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()) {
this.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()) {
this.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()) {
this.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()) {
this.getNodeService().removeChild(assoc.getParentRef(), assoc.getChildRef());
}
}
return outcome;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.
the class Node method getAssociations.
/**
* @return All the associations this node has as a Map, using the association
* type as the key
*/
public final Map getAssociations() {
if (this.assocsRetrieved == false) {
this.associations = new QNameNodeMap(this, this);
List<AssociationRef> assocs = getServiceRegistry().getNodeService().getTargetAssocs(this.nodeRef, RegexQNamePattern.MATCH_ALL);
for (AssociationRef assocRef : assocs) {
String assocName = assocRef.getTypeQName().toString();
List<AssociationRef> list = (List<AssociationRef>) this.associations.get(assocName);
// create the list if this is first association with 'assocName'
if (list == null) {
list = new ArrayList<AssociationRef>();
this.associations.put(assocName, list);
}
// add the association to the list
list.add(assocRef);
}
this.assocsRetrieved = true;
}
return this.associations;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-remote-api by Alfresco.
the class NodeBrowserPost method getAssocs.
/**
* Gets the current node associations
*
* @return associations
*/
public List<PeerAssociation> getAssocs(NodeRef nodeRef) {
List<AssociationRef> refs = null;
try {
refs = getNodeService().getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
} catch (UnsupportedOperationException err) {
// some stores do not support associations
// but we doesn't want NPE in code below
refs = new ArrayList<AssociationRef>();
}
List<PeerAssociation> assocs = new ArrayList<PeerAssociation>(refs.size());
for (AssociationRef ref : refs) {
assocs.add(new PeerAssociation(ref.getTypeQName(), ref.getSourceRef(), ref.getTargetRef()));
}
return assocs;
}
Aggregations