Search in sources :

Example 76 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method addCustomConstraintDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#addCustomConstraintDefinition(org.alfresco.service.namespace.QName, java.lang.String, boolean, java.util.List, org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint.MatchLogic)
 */
public void addCustomConstraintDefinition(QName constraintName, String title, boolean caseSensitive, List<String> allowedValues, MatchLogic matchLogic) {
    mandatory("constraintName", constraintName);
    mandatoryString("title", title);
    mandatory("allowedValues", allowedValues);
    mandatory("matchLogic", matchLogic);
    NodeRef modelRef = getCustomModelRef(constraintName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    String constraintNameAsPrefixString = constraintName.toPrefixString(getNamespaceService());
    M2Constraint customConstraint = deserializedModel.getConstraint(constraintNameAsPrefixString);
    if (customConstraint != null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CONSTRAINT_EXISTS, constraintNameAsPrefixString));
    }
    M2Constraint newCon = deserializedModel.createConstraint(constraintNameAsPrefixString, CUSTOM_CONSTRAINT_TYPE);
    newCon.setTitle(title);
    newCon.createParameter(PARAM_ALLOWED_VALUES, allowedValues);
    newCon.createParameter(PARAM_CASE_SENSITIVE, caseSensitive ? "true" : "false");
    newCon.createParameter(PARAM_MATCH_LOGIC, matchLogic.toString());
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("addCustomConstraintDefinition: " + constraintNameAsPrefixString + " (valueCnt: " + allowedValues.size() + ")");
    }
}
Also used : M2Constraint(org.alfresco.repo.dictionary.M2Constraint) NodeRef(org.alfresco.service.cmr.repository.NodeRef) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)

Example 77 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method updateCustomPropertyDefinitionName.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#updateCustomPropertyDefinitionName(org.alfresco.service.namespace.QName, java.lang.String)
 */
public QName updateCustomPropertyDefinitionName(QName propQName, String newName) throws CustomMetadataException {
    mandatory("propQName", propQName);
    PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
    if (propDefn == null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
    }
    if (newName == null) {
        return propQName;
    }
    QName newPropQName = getQNameForClientId(newName);
    if (newPropQName != null) {
        PropertyDefinition newPropDefn = getDictionaryService().getProperty(newPropQName);
        if (newPropDefn != null && !propDefn.equals(newPropDefn)) {
            // The requested QName is already in use
            String propIdAsString = newPropQName.toPrefixString(getNamespaceService());
            throw new PropertyAlreadyExistsMetadataException(propIdAsString);
        }
    }
    NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    M2Property targetProperty = findProperty(propQName, deserializedModel);
    targetProperty.setName(new StringBuilder().append(RecordsManagementCustomModel.RM_CUSTOM_PREFIX).append(QName.NAMESPACE_PREFIX).append(newName).toString());
    targetProperty.setTitle(URLDecoder.decode(newName));
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("setCustomPropertyDefinitionLabel: " + propQName + "=" + newName);
    }
    return propQName;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 78 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method removeCustomPropertyDefinitionConstraints.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#removeCustomPropertyDefinitionConstraints(org.alfresco.service.namespace.QName)
 */
public QName removeCustomPropertyDefinitionConstraints(QName propQName) {
    mandatory("propQName", propQName);
    PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
    if (propDefn == null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
    }
    NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    M2Property targetProperty = findProperty(propQName, deserializedModel);
    // Need to count backwards to remove constraints
    for (int i = targetProperty.getConstraints().size() - 1; i >= 0; i--) {
        String ref = targetProperty.getConstraints().get(i).getRef();
        targetProperty.removeConstraintRef(ref);
    }
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("removeCustomPropertyDefinitionConstraints: " + propQName);
    }
    return propQName;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) RMListOfValuesConstraint(org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint) Constraint(org.alfresco.service.cmr.dictionary.Constraint) M2Constraint(org.alfresco.repo.dictionary.M2Constraint)

Example 79 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method setCustomPropertyDefinitionConstraint.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#setCustomPropertyDefinitionConstraint(org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName)
 */
public QName setCustomPropertyDefinitionConstraint(QName propQName, QName newLovConstraint) {
    mandatory("propQName", propQName);
    mandatory("newLovConstraint", newLovConstraint);
    PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
    if (propDefn == null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
    }
    NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    M2Property targetProp = findProperty(propQName, deserializedModel);
    String dataType = targetProp.getType();
    if (!dataType.equals(DataTypeDefinition.TEXT.toPrefixString(getNamespaceService()))) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(CannotApplyConstraintMetadataException.MSG_CANNOT_APPLY_CONSTRAINT, newLovConstraint, targetProp.getName(), dataType));
    }
    String lovConstraintQNameAsString = newLovConstraint.toPrefixString(getNamespaceService());
    // Add the constraint - if it isn't already there (there should only be one constraint).
    String refOfExistingConstraint = (targetProp.getConstraints().isEmpty() ? null : targetProp.getConstraints().get(0).getRef());
    if (refOfExistingConstraint != null) {
        targetProp.removeConstraintRef(refOfExistingConstraint);
    }
    targetProp.addConstraintRef(lovConstraintQNameAsString);
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("addCustomPropertyDefinitionConstraint: " + lovConstraintQNameAsString);
    }
    return propQName;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 80 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class RecordsManagementAuditServiceImpl method getAuditTrail.

/**
 * {@inheritDoc}
 */
@Override
public List<RecordsManagementAuditEntry> getAuditTrail(RecordsManagementAuditQueryParameters params) {
    ParameterCheck.mandatory("params", params);
    List<RecordsManagementAuditEntry> entries = new ArrayList<RecordsManagementAuditEntry>(50);
    try {
        getAuditTrailImpl(params, entries, null, null);
        // Done
        return entries;
    } catch (IOException e) {
        // Should be
        throw new AlfrescoRuntimeException(MSG_TRAIL_FILE_FAIL, e);
    }
}
Also used : ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)197 NodeRef (org.alfresco.service.cmr.repository.NodeRef)79 QName (org.alfresco.service.namespace.QName)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)32 ArrayList (java.util.ArrayList)31 JSONException (org.json.JSONException)23 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Serializable (java.io.Serializable)20 M2Model (org.alfresco.repo.dictionary.M2Model)18 JSONObject (org.json.JSONObject)15 Date (java.util.Date)14 Map (java.util.Map)12 FacesContext (javax.faces.context.FacesContext)12 InputStream (java.io.InputStream)10 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)10 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)10 JSONArray (org.json.JSONArray)10 List (java.util.List)8 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)8