Search in sources :

Example 21 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.

the class BaseActionWizard method getObjectTypes.

/**
 * @return Returns a list of object types to allow the user to select from
 */
public List<SelectItem> getObjectTypes() {
    if ((this.objectTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        // add the well known object type to start with
        this.objectTypes = new ArrayList<SelectItem>(5);
        // add any configured content or folder sub-types to the list
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement typesCfg = wizardCfg.getConfigElement("specialise-types");
            if (typesCfg != null) {
                for (ConfigElement child : typesCfg.getChildren()) {
                    QName idQName = Repository.resolveToQName(child.getAttribute("name"));
                    TypeDefinition typeDef = this.getDictionaryService().getType(idQName);
                    // the content or folder type itself
                    if (typeDef != null && typeDef.getName().equals(ContentModel.TYPE_CONTENT) == false && typeDef.getName().equals(ContentModel.TYPE_FOLDER) == false && (this.getDictionaryService().isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT) || this.getDictionaryService().isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER))) {
                        // try and get the display label from config
                        String label = Utils.getDisplayLabel(context, child);
                        // if there wasn't a client based label try and get it from the dictionary
                        if (label == null) {
                            label = typeDef.getTitle(this.getDictionaryService());
                        }
                        // finally, just use the localname
                        if (label == null) {
                            label = idQName.getLocalName();
                        }
                        this.objectTypes.add(new SelectItem(idQName.toString(), label));
                    }
                }
                // make sure the list is sorted by the label
                QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
                // add the select an action item at the start of the list
                this.objectTypes.add(0, new SelectItem("null", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_type")));
            } else {
                logger.warn("Could not find 'specialise-types' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
    return this.objectTypes;
}
Also used : FacesContext(javax.faces.context.FacesContext) QuickSort(org.alfresco.web.data.QuickSort) ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) SelectItem(javax.faces.model.SelectItem) Config(org.springframework.extensions.config.Config) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 22 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition 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());
            }
        }
    }
}
Also used : DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QName(org.alfresco.service.namespace.QName) CustomProperty(org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) AdvancedSearchConfigElement(org.alfresco.web.config.AdvancedSearchConfigElement) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 23 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.

the class AdvancedSearchDialog method getFolderTypes.

/**
 * @return Returns a list of folder object types to allow the user to select from
 */
public List<SelectItem> getFolderTypes() {
    if ((properties.getFolderTypes() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
        // add the well known cm:folder object type by default
        properties.setFolderTypes(new ArrayList<SelectItem>(5));
        properties.getFolderTypes().add(new SelectItem(ContentModel.TYPE_FOLDER.toString(), dictionaryService.getType(ContentModel.TYPE_FOLDER).getTitle(dictionaryService)));
        // add any configured folder sub-types to the list
        List<String> types = getSearchConfig().getFolderTypes();
        if (types != null) {
            for (String type : types) {
                QName idQName = Repository.resolveToQName(type);
                if (idQName != null) {
                    TypeDefinition typeDef = dictionaryService.getType(idQName);
                    if (typeDef != null && dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER)) {
                        // try and get label from the dictionary
                        String label = typeDef.getTitle(dictionaryService);
                        // else just use the localname
                        if (label == null) {
                            label = idQName.getLocalName();
                        }
                        properties.getFolderTypes().add(new SelectItem(idQName.toString(), label));
                    }
                }
            }
        }
    }
    return properties.getFolderTypes();
}
Also used : FacesContext(javax.faces.context.FacesContext) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) SelectItem(javax.faces.model.SelectItem) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 24 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.

the class CreateSpaceWizard method getFolderTypes.

/**
 * Returns a list of UIListItem objects representing the folder types
 * and also constructs the list of descriptions for each type
 *
 * @return List of UIListItem components
 */
@SuppressWarnings("unchecked")
public List<UIListItem> getFolderTypes() {
    if ((this.folderTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        this.folderTypes = new ArrayList<UIListItem>(2);
        this.folderTypeDescriptions = new ArrayList<UIDescription>(2);
        // add the well known 'container space' type to start with
        UIListItem defaultItem = new UIListItem();
        String defaultLabel = Application.getMessage(context, "container");
        defaultItem.setValue(ContentModel.TYPE_FOLDER.toString());
        defaultItem.setLabel(defaultLabel);
        defaultItem.setTooltip(defaultLabel);
        defaultItem.setImage(DEFAULT_SPACE_TYPE_ICON_PATH);
        this.folderTypes.add(defaultItem);
        UIDescription defaultDesc = new UIDescription();
        defaultDesc.setControlValue(ContentModel.TYPE_FOLDER.toString());
        defaultDesc.setText(Application.getMessage(context, "container_desc"));
        this.folderTypeDescriptions.add(defaultDesc);
        // add any configured content sub-types to the list
        Config wizardCfg = Application.getConfigService(FacesContext.getCurrentInstance()).getConfig("Space Wizards");
        if (wizardCfg != null) {
            ConfigElement typesCfg = wizardCfg.getConfigElement("folder-types");
            if (typesCfg != null) {
                for (ConfigElement child : typesCfg.getChildren()) {
                    QName idQName = Repository.resolveToQName(child.getAttribute("name"));
                    if (idQName != null) {
                        TypeDefinition typeDef = this.getDictionaryService().getType(idQName);
                        if (typeDef != null) {
                            if (this.getDictionaryService().isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER)) {
                                // try and get the label from config
                                String label = Utils.getDisplayLabel(context, child);
                                // if there wasn't a client based label try and get it from the dictionary
                                if (label == null) {
                                    label = typeDef.getTitle(this.getDictionaryService());
                                }
                                // finally use the localname if we still haven't found a label
                                if (label == null) {
                                    label = idQName.getLocalName();
                                }
                                // resolve a description string for the type
                                String description = Utils.getDescription(context, child);
                                // if we don't have a local description just use the label
                                if (description == null) {
                                    description = label;
                                }
                                // extract the icon to use from the config
                                String icon = child.getAttribute("icon");
                                if (icon == null || icon.length() == 0) {
                                    icon = DEFAULT_SPACE_TYPE_ICON_PATH;
                                }
                                UIListItem item = new UIListItem();
                                item.setValue(idQName.toString());
                                item.setLabel(label);
                                item.setTooltip(label);
                                item.setImage(icon);
                                this.folderTypes.add(item);
                                UIDescription desc = new UIDescription();
                                desc.setControlValue(idQName.toString());
                                desc.setText(description);
                                this.folderTypeDescriptions.add(desc);
                            } else {
                                logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of folder types as the type is not a subtype of cm:folder");
                            }
                        } else {
                            logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of folder types as the type is not recognised");
                        }
                    } else {
                        logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of folder types as the prefix can not be resolved");
                    }
                }
            } else {
                logger.warn("Could not find 'folder-types' configuration element");
            }
        } else {
            logger.warn("Could not find 'Space Wizards' configuration section");
        }
    }
    return this.folderTypes;
}
Also used : UIDescription(org.alfresco.web.ui.common.component.description.UIDescription) FacesContext(javax.faces.context.FacesContext) UIListItem(org.alfresco.web.ui.common.component.UIListItem) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 25 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.

the class DeleteSpaceDialog method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    final boolean isAdmin = this.navigator.getCurrentUser().isAdmin();
    // get the space to delete
    Node node = this.browseBean.getActionSpace();
    if (node != null) {
        // force cache of name property so we can use it after the delete
        node.getName();
        if (logger.isDebugEnabled())
            logger.debug("Trying to delete space: " + node.getId() + " using delete mode: " + this.deleteMode);
        try {
            if (isAdmin && !this.executeRules) {
                Repository.getServiceRegistry(context).getRuleService().disableRules();
            }
            if (DELETE_ALL.equals(this.deleteMode)) {
                NodeRef nodeRef = node.getNodeRef();
                // Check the node still exists
                if (this.getNodeService().exists(nodeRef)) {
                    if (isAdmin && !this.archiveNodes) {
                        this.getNodeService().addAspect(node.getNodeRef(), ContentModel.ASPECT_TEMPORARY, null);
                    }
                    // ensure the node still exists before deleting
                    if (this.getNodeService().exists(node.getNodeRef())) {
                        this.getNodeService().deleteNode(node.getNodeRef());
                    }
                }
            } else {
                List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(node.getNodeRef(), ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
                List<NodeRef> deleteRefs = new ArrayList<NodeRef>(childRefs.size());
                for (ChildAssociationRef ref : childRefs) {
                    NodeRef nodeRef = ref.getChildRef();
                    if (this.getNodeService().exists(nodeRef)) {
                        if (DELETE_CONTENTS.equals(this.deleteMode)) {
                            deleteRefs.add(nodeRef);
                        } else {
                            // find it's type so we can see if it's a node we are interested in
                            QName type = this.getNodeService().getType(nodeRef);
                            // make sure the type is defined in the data dictionary
                            TypeDefinition typeDef = this.getDictionaryService().getType(type);
                            if (typeDef != null) {
                                if (DELETE_FOLDERS.equals(this.deleteMode)) {
                                    // look for folder type
                                    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                                        deleteRefs.add(nodeRef);
                                    }
                                } else if (DELETE_FILES.equals(this.deleteMode)) {
                                    // look for content file type
                                    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
                                        deleteRefs.add(nodeRef);
                                    }
                                }
                            }
                        }
                    }
                }
                // delete the list of refs
                TransactionService txService = Repository.getServiceRegistry(context).getTransactionService();
                for (NodeRef nodeRef : deleteRefs) {
                    UserTransaction tx = null;
                    try {
                        tx = txService.getNonPropagatingUserTransaction();
                        tx.begin();
                        if (isAdmin && !this.archiveNodes) {
                            this.getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
                        }
                        // ensure the node still exists before deleting
                        if (this.getNodeService().exists(node.getNodeRef())) {
                            this.getNodeService().deleteNode(nodeRef);
                        }
                        tx.commit();
                    } catch (Throwable err) {
                        try {
                            if (tx != null) {
                                tx.rollback();
                            }
                        } catch (Exception ex) {
                        }
                    }
                }
            }
        } finally {
            if (isAdmin && !this.executeRules) {
                Repository.getServiceRegistry(context).getRuleService().enableRules();
            }
        }
    } else {
        logger.warn("WARNING: delete called without a current Space!");
    }
    return outcome;
}
Also used : UserTransaction(javax.transaction.UserTransaction) TransactionService(org.alfresco.service.transaction.TransactionService) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)43 QName (org.alfresco.service.namespace.QName)30 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 FacesContext (javax.faces.context.FacesContext)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 StartFormData (org.activiti.engine.form.StartFormData)8 IOException (java.io.IOException)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 Node (org.alfresco.web.bean.repository.Node)7 UserTransaction (javax.transaction.UserTransaction)6 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)6 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 Date (java.util.Date)5 SelectItem (javax.faces.model.SelectItem)5 MapNode (org.alfresco.web.bean.repository.MapNode)5 Serializable (java.io.Serializable)4 List (java.util.List)4