Search in sources :

Example 1 with AbstractClassModel

use of org.alfresco.rest.api.model.AbstractClassModel in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method replacePrefix.

private void replacePrefix(List<? extends AbstractClassModel> existingTypesOrAspects, String modelOldNamespacePrefix, String modelNewNamespacePrefix) {
    for (AbstractClassModel classModel : existingTypesOrAspects) {
        // Type/Aspect's parent name
        String parentName = classModel.getParentName();
        if (parentName != null) {
            Pair<String, String> prefixLocalNamePair = splitPrefixedQName(parentName);
            // As we don't want to modify the parent name of the imported models.
            if (modelOldNamespacePrefix.equals(prefixLocalNamePair.getFirst())) {
                // Change the parent name prefix, to a new model namespace prefix.
                String newParentName = constructName(prefixLocalNamePair.getSecond(), modelNewNamespacePrefix);
                classModel.setParentName(newParentName);
            }
        }
        // Change the property constraint ref
        List<CustomModelProperty> properties = classModel.getProperties();
        for (CustomModelProperty prop : properties) {
            List<String> constraintRefs = prop.getConstraintRefs();
            if (constraintRefs.size() > 0) {
                List<String> modifiedRefs = new ArrayList<>(constraintRefs.size());
                for (String ref : constraintRefs) {
                    // We don't need to check if the prefix is equal to the model prefix here, as it was
                    // done upon adding the constraint refs in the setM2Properties method.
                    Pair<String, String> prefixLocalNamePair = splitPrefixedQName(ref);
                    // Change the constraint ref prefix, to a new model namespace prefix.
                    String newRef = constructName(prefixLocalNamePair.getSecond(), modelNewNamespacePrefix);
                    modifiedRefs.add(newRef);
                }
                prop.setConstraintRefs(modifiedRefs);
            }
        }
    }
}
Also used : AbstractClassModel(org.alfresco.rest.api.model.AbstractClassModel) ArrayList(java.util.ArrayList) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty)

Example 2 with AbstractClassModel

use of org.alfresco.rest.api.model.AbstractClassModel in project alfresco-remote-api by Alfresco.

the class BaseCustomModelApiTest method createTypeAspect.

protected <T extends AbstractClassModel> T createTypeAspect(Class<T> glazz, String modelName, String typeAspectName, String title, String desc, String parent) throws Exception {
    AbstractClassModel classModel = null;
    String uri = "cmm/" + modelName;
    if (glazz.equals(CustomType.class)) {
        classModel = new CustomType();
        uri += "/types";
    } else {
        classModel = new CustomAspect();
        uri += "/aspects";
    }
    classModel.setName(typeAspectName);
    classModel.setDescription(desc);
    classModel.setTitle(title);
    classModel.setParentName(parent);
    // Create type as a Model Administrator
    HttpResponse response = post(uri, RestApiUtil.toJsonAsString(classModel), 201);
    T returnedClassModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), glazz);
    compareCustomTypesAspects(classModel, returnedClassModel, "prefixedName");
    return returnedClassModel;
}
Also used : CustomType(org.alfresco.rest.api.model.CustomType) AbstractClassModel(org.alfresco.rest.api.model.AbstractClassModel) CustomAspect(org.alfresco.rest.api.model.CustomAspect) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse)

Aggregations

AbstractClassModel (org.alfresco.rest.api.model.AbstractClassModel)2 ArrayList (java.util.ArrayList)1 CustomAspect (org.alfresco.rest.api.model.CustomAspect)1 CustomModelProperty (org.alfresco.rest.api.model.CustomModelProperty)1 CustomType (org.alfresco.rest.api.model.CustomType)1 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)1