Search in sources :

Example 6 with ConstraintDefinition

use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project records-management by Alfresco.

the class RMCaveatConfigServiceImpl method getRMConstraint.

/**
 * Get an RMConstraintInfo
 * @param listQName
 * @return the constraint or null if it does not exist
 */
public RMConstraintInfo getRMConstraint(QName listQName) {
    ConstraintDefinition dictionaryDef = dictionaryService.getConstraint(listQName);
    if (dictionaryDef != null) {
        Constraint con = dictionaryDef.getConstraint();
        if (con instanceof RMListOfValuesConstraint) {
            final RMListOfValuesConstraint def = (RMListOfValuesConstraint) con;
            RMConstraintInfo info = new RMConstraintInfo();
            info.setName(listQName.toPrefixString());
            info.setTitle(con.getTitle());
            List<String> allowedValues = AuthenticationUtil.runAs(new RunAsWork<List<String>>() {

                public List<String> doWork() {
                    return def.getAllowedValues();
                }
            }, AuthenticationUtil.getSystemUserName());
            info.setAllowedValues(allowedValues.toArray(new String[allowedValues.size()]));
            info.setCaseSensitive(def.isCaseSensitive());
            return info;
        }
    }
    return null;
}
Also used : Constraint(org.alfresco.service.cmr.dictionary.Constraint) ArrayList(java.util.ArrayList) List(java.util.List) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 7 with ConstraintDefinition

use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method getCustomConstraintDefinitions.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#getCustomConstraintDefinitions(org.alfresco.service.namespace.QName)
 */
public List<ConstraintDefinition> getCustomConstraintDefinitions(QName modelQName) {
    mandatory("modelQName", modelQName);
    Collection<ConstraintDefinition> conDefs = getDictionaryService().getConstraints(modelQName, true);
    for (ConstraintDefinition conDef : conDefs) {
        Constraint con = conDef.getConstraint();
        if (!(con instanceof RMListOfValuesConstraint)) {
            conDefs.remove(conDef);
        }
    }
    return new ArrayList<ConstraintDefinition>(conDefs);
}
Also used : RMListOfValuesConstraint(org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint) Constraint(org.alfresco.service.cmr.dictionary.Constraint) M2Constraint(org.alfresco.repo.dictionary.M2Constraint) RMListOfValuesConstraint(org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint) ArrayList(java.util.ArrayList) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 8 with ConstraintDefinition

use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project records-management by Alfresco.

the class CustomPropertyDefinitionPut method updatePropertyDefinition.

/**
 * If label has a non-null value, it is set on the property def.
 * If constraintRef has a non-null value, it is set on this propDef.
 * If constraintRef has a null value, all constraints for that propDef are removed.
 *
 * @param params
 * @return
 * @throws CustomMetadataException
 */
protected QName updatePropertyDefinition(Map<String, Serializable> params) throws CustomMetadataException {
    QName result = null;
    boolean updated = false;
    String propId = (String) params.get(PROP_ID);
    ParameterCheck.mandatoryString("propId", propId);
    QName propQName = rmAdminService.getQNameForClientId(propId);
    if (propQName == null) {
        propQName = rmAdminService.getQNameForClientId(URLEncoder.encode(propId));
    }
    if (propQName == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Could not find property definition for: " + propId);
    }
    if (params.containsKey(PARAM_CONSTRAINT_REF)) {
        String constraintRef = (String) params.get(PARAM_CONSTRAINT_REF);
        List<ConstraintDefinition> constraints = rmAdminService.getCustomPropertyDefinitions().get(propQName).getConstraints();
        if (constraintRef == null) {
            result = rmAdminService.removeCustomPropertyDefinitionConstraints(propQName);
            updated = constraints.isEmpty() ? false : true;
        } else {
            boolean exists = false;
            for (ConstraintDefinition constraintDefinition : constraints) {
                if (constraintDefinition.getConstraint().getShortName().equalsIgnoreCase(constraintRef)) {
                    exists = true;
                    break;
                }
            }
            if (!exists) {
                QName constraintRefQName = QName.createQName(constraintRef, getNamespaceService());
                result = rmAdminService.setCustomPropertyDefinitionConstraint(propQName, constraintRefQName);
                updated = true;
            }
        }
    }
    if (params.containsKey(PARAM_LABEL)) {
        String label = (String) params.get(PARAM_LABEL);
        try {
            result = rmAdminService.updateCustomPropertyDefinitionName(propQName, label);
        } catch (PropertyAlreadyExistsMetadataException ex) {
            if (!updated) {
                String propIdAsString = rmAdminService.getQNameForClientId(label).toPrefixString(getNamespaceService());
                throw new PropertyAlreadyExistsMetadataException(propIdAsString);
            }
        }
    }
    return result;
}
Also used : PropertyAlreadyExistsMetadataException(org.alfresco.module.org_alfresco_module_rm.admin.PropertyAlreadyExistsMetadataException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) QName(org.alfresco.service.namespace.QName) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 9 with ConstraintDefinition

use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method createCustomModel.

@Override
public CustomModel createCustomModel(M2Model m2Model) {
    // Check the current user is authorised to import the custom model
    validateCurrentUser();
    validateImportedM2Model(m2Model);
    CompiledModel compiledModel = null;
    try {
        compiledModel = customModelService.compileModel(m2Model);
    } catch (CustomModelConstraintException mce) {
        throw new ConstraintViolatedException(mce.getMessage());
    } catch (InvalidCustomModelException iex) {
        throw new InvalidArgumentException(iex.getMessage());
    }
    ModelDefinition modelDefinition = compiledModel.getModelDefinition();
    CustomModel customModel = new CustomModel();
    customModel.setName(modelDefinition.getName().getLocalName());
    customModel.setAuthor(modelDefinition.getAuthor());
    customModel.setDescription(modelDefinition.getDescription(dictionaryService));
    customModel.setStatus(ModelStatus.DRAFT);
    NamespaceDefinition nsd = modelDefinition.getNamespaces().iterator().next();
    customModel.setNamespaceUri(nsd.getUri());
    customModel.setNamespacePrefix(nsd.getPrefix());
    List<CustomType> customTypes = convertToCustomTypes(compiledModel.getTypes(), false);
    List<CustomAspect> customAspects = convertToCustomAspects(compiledModel.getAspects(), false);
    List<ConstraintDefinition> constraintDefinitions = CustomModelDefinitionImpl.removeInlineConstraints(compiledModel);
    List<CustomModelConstraint> customModelConstraints = convertToCustomModelConstraints(constraintDefinitions);
    customModel.setTypes(customTypes);
    customModel.setAspects(customAspects);
    customModel.setConstraints(customModelConstraints);
    return createCustomModelImpl(customModel, false);
}
Also used : CustomType(org.alfresco.rest.api.model.CustomType) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) CustomAspect(org.alfresco.rest.api.model.CustomAspect) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) CustomModel(org.alfresco.rest.api.model.CustomModel) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) CompiledModel(org.alfresco.repo.dictionary.CompiledModel) ModelDefinition(org.alfresco.service.cmr.dictionary.ModelDefinition) CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) NamespaceDefinition(org.alfresco.service.cmr.dictionary.NamespaceDefinition) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint)

Example 10 with ConstraintDefinition

use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project alfresco-remote-api by Alfresco.

the class WorkflowRestImpl method getFormModelElements.

/**
 * @param type the type to get the elements for
 * @param paging Paging
 * @return collection with all valid form-model elements for the given type.
 */
public CollectionWithPagingInfo<FormModelElement> getFormModelElements(TypeDefinition type, Paging paging) {
    Map<QName, PropertyDefinition> taskProperties = type.getProperties();
    Set<QName> typesToExclude = getTypesToExclude(type);
    List<FormModelElement> page = new ArrayList<FormModelElement>();
    for (Entry<QName, PropertyDefinition> entry : taskProperties.entrySet()) {
        String name = entry.getKey().toPrefixString(namespaceService).replace(':', '_');
        // Only add properties which are not part of an excluded type
        if (!typesToExclude.contains(entry.getValue().getContainerClass().getName()) && excludeModelTypes.contains(name) == false) {
            FormModelElement element = new FormModelElement();
            element.setName(name);
            element.setQualifiedName(entry.getKey().toString());
            element.setTitle(entry.getValue().getTitle(dictionaryService));
            element.setRequired(entry.getValue().isMandatory());
            element.setDataType(entry.getValue().getDataType().getName().toPrefixString(namespaceService));
            element.setDefaultValue(entry.getValue().getDefaultValue());
            if (entry.getValue().getConstraints() != null) {
                for (ConstraintDefinition constraintDef : entry.getValue().getConstraints()) {
                    Constraint constraint = constraintDef.getConstraint();
                    if (constraint != null && constraint instanceof ListOfValuesConstraint) {
                        ListOfValuesConstraint valuesConstraint = (ListOfValuesConstraint) constraint;
                        if (valuesConstraint.getAllowedValues() != null && valuesConstraint.getAllowedValues().size() > 0) {
                            element.setAllowedValues(valuesConstraint.getAllowedValues());
                        }
                    }
                }
            }
            page.add(element);
        }
    }
    Map<QName, AssociationDefinition> taskAssociations = type.getAssociations();
    for (Entry<QName, AssociationDefinition> entry : taskAssociations.entrySet()) {
        // Only add associations which are not part of an excluded type
        if (!typesToExclude.contains(entry.getValue().getSourceClass().getName())) {
            FormModelElement element = new FormModelElement();
            element.setName(entry.getKey().toPrefixString(namespaceService).replace(':', '_'));
            element.setQualifiedName(entry.getKey().toString());
            element.setTitle(entry.getValue().getTitle(dictionaryService));
            element.setRequired(entry.getValue().isTargetMandatory());
            element.setDataType(entry.getValue().getTargetClass().getName().toPrefixString(namespaceService));
            page.add(element);
        }
    }
    return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
Also used : FormModelElement(org.alfresco.rest.workflow.api.model.FormModelElement) Constraint(org.alfresco.service.cmr.dictionary.Constraint) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)

Aggregations

ConstraintDefinition (org.alfresco.service.cmr.dictionary.ConstraintDefinition)15 Constraint (org.alfresco.service.cmr.dictionary.Constraint)11 ArrayList (java.util.ArrayList)10 QName (org.alfresco.service.namespace.QName)9 List (java.util.List)8 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)5 ListOfValuesConstraint (org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)3 CustomModelConstraint (org.alfresco.rest.api.model.CustomModelConstraint)3 CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 RMListOfValuesConstraint (org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint)2 MimetypeMap (org.alfresco.repo.content.MimetypeMap)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 JSONObject (org.json.JSONObject)2 Serializable (java.io.Serializable)1 Entry (java.util.Map.Entry)1 AccessDeniedException (net.sf.acegisecurity.AccessDeniedException)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1