use of org.alfresco.service.cmr.dictionary.CustomModelDefinition in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method getCustomAspect.
@Override
public CustomAspect getCustomAspect(String modelName, String aspectName, Parameters parameters) {
if (aspectName == null) {
throw new InvalidArgumentException(ASPECT_NAME_NULL_ERR);
}
final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
QName aspectQname = QName.createQName(modelDef.getName().getNamespaceURI(), aspectName);
AspectDefinition customAspectDef = customModelService.getCustomAspect(aspectQname);
if (customAspectDef == null) {
throw new EntityNotFoundException(aspectName);
}
// Check if inherited properties have been requested
boolean includeInheritedProps = hasSelectProperty(parameters, SELECT_ALL_PROPS);
return convertToCustomAspect(customAspectDef, includeInheritedProps);
}
use of org.alfresco.service.cmr.dictionary.CustomModelDefinition in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method getCustomType.
@Override
public CustomType getCustomType(String modelName, String typeName, Parameters parameters) {
if (typeName == null) {
throw new InvalidArgumentException(TYPE_NAME_NULL_ERR);
}
final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
QName typeQname = QName.createQName(modelDef.getName().getNamespaceURI(), typeName);
TypeDefinition customTypeDef = customModelService.getCustomType(typeQname);
if (customTypeDef == null) {
throw new EntityNotFoundException(typeName);
}
// Check if inherited properties have been requested
boolean includeInheritedProps = hasSelectProperty(parameters, SELECT_ALL_PROPS);
return convertToCustomType(customTypeDef, includeInheritedProps);
}
use of org.alfresco.service.cmr.dictionary.CustomModelDefinition in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method updateCustomModel.
@Override
public CustomModel updateCustomModel(String modelName, CustomModel model, Parameters parameters) {
// Check the current user is authorised to update the custom model
validateCurrentUser();
// Check to see if the model exists
ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
CustomModel existingModel = existingModelDetails.getModel();
// the other properties should be untouched)
if (hasSelectProperty(parameters, SELECT_STATUS)) {
ModelStatus status = model.getStatus();
if (status == null) {
throw new InvalidArgumentException("cmm.rest_api.model_status_null");
}
try {
if (ModelStatus.ACTIVE.equals(status)) {
customModelService.activateCustomModel(modelName);
} else {
customModelService.deactivateCustomModel(modelName);
}
// update the model's status
existingModel.setStatus(status);
return existingModel;
} catch (CustomModelConstraintException mce) {
throw new ConstraintViolatedException(mce.getMessage());
} catch (Exception ex) {
throw new ApiException(ex.getMessage(), ex);
}
} else {
if (model.getName() != null && !(existingModel.getName().equals(model.getName()))) {
throw new InvalidArgumentException("cmm.rest_api.model_name_cannot_update");
}
existingModel.setNamespaceUri(model.getNamespaceUri());
final boolean isNamespacePrefixChanged = !(existingModel.getNamespacePrefix().equals(model.getNamespacePrefix()));
if (isNamespacePrefixChanged) {
// Change types' and aspects' parents as well as the property constraint's Ref namespace prefix
replacePrefix(existingModelDetails.getTypes(), existingModel.getNamespacePrefix(), model.getNamespacePrefix());
replacePrefix(existingModelDetails.getAspects(), existingModel.getNamespacePrefix(), model.getNamespacePrefix());
}
existingModel.setNamespacePrefix(model.getNamespacePrefix());
existingModel.setAuthor(model.getAuthor());
existingModel.setDescription(model.getDescription());
CustomModelDefinition modelDef = updateModel(existingModelDetails, "cmm.rest_api.model_update_failure");
return new CustomModel(modelDef);
}
}
use of org.alfresco.service.cmr.dictionary.CustomModelDefinition in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method getCustomTypes.
@Override
public CollectionWithPagingInfo<CustomType> getCustomTypes(String modelName, Parameters parameters) {
CustomModelDefinition modelDef = getCustomModelImpl(modelName);
Collection<TypeDefinition> typeDefinitions = modelDef.getTypeDefinitions();
// TODO Should we support paging?
Paging paging = Paging.DEFAULT;
List<CustomType> customTypes = convertToCustomTypes(typeDefinitions, false);
return CollectionWithPagingInfo.asPaged(paging, customTypes, false, typeDefinitions.size());
}
use of org.alfresco.service.cmr.dictionary.CustomModelDefinition in project alfresco-remote-api by Alfresco.
the class TestCustomTypeAspect method testCreateAspectsAndTypes_ExistingModel.
@Test
public void testCreateAspectsAndTypes_ExistingModel() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModel" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
final String aspectName = "testAspect1" + System.currentTimeMillis();
{
// Add aspect
CustomAspect aspect = new CustomAspect();
aspect.setName(aspectName);
setRequestContext(nonAdminUserName);
// Try to create aspect as a non Admin user
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 403);
setRequestContext(customModelAdmin);
// Set the aspect's parent with a type name!
aspect.setParentName("cm:content");
// Try to create an invalid aspect as a Model Administrator
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409);
// Create aspect as a Model Administrator
aspect.setParentName(null);
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 201);
// Create the aspect again - duplicate name
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409);
// Retrieve the created aspect
HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
compareCustomTypesAspects(aspect, returnedAspect, "prefixedName");
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + aspectName, returnedAspect.getPrefixedName());
}
String typeName = "testType" + System.currentTimeMillis();
{
// Add type
CustomType type = new CustomType();
type.setName(typeName);
type.setDescription("test type Desc");
type.setTitle("test type title");
type.setParentName("cm:content");
setRequestContext(nonAdminUserName);
// Try to create type as a non Admin user
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 403);
setRequestContext(customModelAdmin);
// Set the type's parent with an aspect name!
type.setParentName("cm:titled");
// Try to create an invalid type as a Model Administrator
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409);
// Create type as a Model Administrator
type.setParentName("cm:content");
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 201);
// Create the type again - duplicate name
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409);
// Retrieve the created type
HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
compareCustomTypesAspects(type, returnedType, "prefixedName");
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeName, returnedType.getPrefixedName());
// for now this is the simplest way to check for the imported namespaces
CustomModelDefinition modelDef = getModelDefinition(modelName);
assertNotNull(modelDef);
Collection<NamespaceDefinition> importedNamespaces = modelDef.getImportedNamespaces();
assertTrue(hasNamespaceUri(importedNamespaces, "http://www.alfresco.org/model/content/1.0"));
assertTrue(hasNamespacePrefix(importedNamespaces, "cm"));
}
// Existing name
{
// Add aspect
CustomAspect aspect = new CustomAspect();
// Set the aspect name with an existing type name. The model
// cannot have a type and an aspect with the same name.
aspect.setName(typeName);
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409);
CustomType type = new CustomType();
// Set the type name with an existing aspect name
type.setName(aspectName);
type.setParentName("cm:content");
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409);
}
}
Aggregations