use of org.alfresco.service.cmr.dictionary.PropertyDefinition 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.dictionary.PropertyDefinition in project acs-community-packaging by Alfresco.
the class UISearchCustomProperties method createComponentsFromConfig.
/**
* Build the components from the Advanced Search config entries
*
* @param context FacesContext
*/
@SuppressWarnings("unchecked")
private void createComponentsFromConfig(FacesContext context) {
DictionaryService dd = Repository.getServiceRegistry(context).getDictionaryService();
AdvancedSearchConfigElement config = (AdvancedSearchConfigElement) Application.getConfigService(context).getConfig("Advanced Search").getConfigElement(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID);
// create an appropriate component for each custom property
// using the DataDictionary to look-up labels and value types
String beanBinding = (String) getAttributes().get("bean") + '.' + (String) getAttributes().get("var");
List<CustomProperty> props = config.getCustomProperties();
if (props != null) {
for (CustomProperty property : props) {
try {
// try to find the Property definition for the specified Type or Aspect
PropertyDefinition propDef = null;
if (property.Type != null) {
QName type = Repository.resolveToQName(property.Type);
TypeDefinition typeDef = dd.getType(type);
if (typeDef == null) {
logger.warn("No Type Definition found for: " + property.Type + " - Was an Aspect expected?");
continue;
}
propDef = typeDef.getProperties().get(Repository.resolveToQName(property.Property));
} else if (property.Aspect != null) {
QName aspect = Repository.resolveToQName(property.Aspect);
AspectDefinition aspectDef = dd.getAspect(aspect);
if (aspectDef == null) {
logger.warn("No Aspect Definition found for: " + property.Aspect + " - Was a Type expected?");
continue;
}
propDef = aspectDef.getProperties().get(Repository.resolveToQName(property.Property));
}
// if we found a def, then we can build components to represent it
if (propDef != null) {
// resolve display label I18N message
String label;
if (property.LabelId != null && property.LabelId.length() != 0) {
label = Application.getMessage(context, property.LabelId);
} else {
// or use dictionary label or QName as last resort
label = propDef.getTitle(dd) != null ? propDef.getTitle(dd) : propDef.getName().getLocalName();
}
// special handling for Date and DateTime
DataTypeDefinition dataTypeDef = propDef.getDataType();
if (DataTypeDefinition.DATE.equals(dataTypeDef.getName()) || DataTypeDefinition.DATETIME.equals(dataTypeDef.getName())) {
getChildren().add(generateControl(context, propDef, label, beanBinding));
} else {
// add ListOfValues constraint components
ListOfValuesConstraint constraint = getListOfValuesConstraint(propDef);
if (constraint != null && propDef != null && propDef.isProtected() == false) {
getChildren().add(generateCheck(context, propDef, beanBinding));
getChildren().add(generateLabel(context, label + ": "));
} else {
getChildren().add(generateLabel(context, ""));
getChildren().add(generateLabel(context, label + ": "));
}
getChildren().add(generateControl(context, propDef, null, beanBinding));
}
}
} catch (DictionaryException ddErr) {
logger.warn("Error building custom properties for Advanced Search: " + ddErr.getMessage());
}
}
}
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project acs-community-packaging by Alfresco.
the class UIProperty method generateItem.
protected void generateItem(FacesContext context, UIPropertySheet propSheet) throws IOException {
Node node = propSheet.getNode();
String propertyName = (String) getName();
DataDictionary dd = (DataDictionary) FacesContextUtils.getRequiredWebApplicationContext(context).getBean(Application.BEAN_DATA_DICTIONARY);
PropertyDefinition propDef = dd.getPropertyDefinition(node, propertyName);
if (propDef == null) {
// Or, if the ignoreIfMissing flag is set to false, show the property
if (node.hasProperty(propertyName) || getIgnoreIfMissing() == false) {
String displayLabel = (String) getDisplayLabel();
if (displayLabel == null) {
displayLabel = propertyName;
}
// generate the label and generic control
generateLabel(context, propSheet, displayLabel);
generateControl(context, propSheet, propertyName);
} else {
// warn the user that the property was not found anywhere
if (missingPropsLogger.isWarnEnabled())
missingPropsLogger.warn("Failed to find property '" + propertyName + "' for node: " + node.getNodeRef().toString());
}
} else {
String displayLabel = (String) getDisplayLabel();
if (displayLabel == null) {
// try and get the repository assigned label
displayLabel = propDef.getTitle(dd.getDictionaryService());
// if the label is still null default to the local name of the property
if (displayLabel == null) {
displayLabel = propDef.getName().getLocalName();
}
}
// generate the label and type specific control
generateLabel(context, propSheet, displayLabel);
generateControl(context, propSheet, propDef);
}
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition 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.dictionary.PropertyDefinition in project acs-community-packaging by Alfresco.
the class StartWorkflowWizard method getPackageItemActionGroup.
/**
* Returns the action group the current task uses for each workflow package item
*
* @return action group id
*/
public String getPackageItemActionGroup() {
String actionGroup = null;
WorkflowDefinition flowDef = this.getWorkflows().get(this.selectedWorkflow);
WorkflowTaskDefinition taskDef = flowDef.getStartTaskDefinition();
if (taskDef != null) {
PropertyDefinition propDef = taskDef.metadata.getProperties().get(WorkflowModel.PROP_PACKAGE_ITEM_ACTION_GROUP);
if (propDef != null) {
actionGroup = propDef.getDefaultValue();
}
}
return actionGroup;
}
Aggregations