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);
}
}
}
}
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;
}
Aggregations