Search in sources :

Example 1 with CustomModelDefinition

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

the class CustomModelsImpl method getCustomModels.

@Override
public CollectionWithPagingInfo<CustomModel> getCustomModels(Parameters parameters) {
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    PagingResults<CustomModelDefinition> results = customModelService.getCustomModels(pagingRequest);
    Integer totalItems = results.getTotalResultCount().getFirst();
    List<CustomModelDefinition> page = results.getPage();
    List<CustomModel> models = new ArrayList<>(page.size());
    for (CustomModelDefinition modelDefinition : page) {
        models.add(new CustomModel(modelDefinition));
    }
    return CollectionWithPagingInfo.asPaged(paging, models, results.hasMoreItems(), (totalItems == null ? null : totalItems.intValue()));
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) PagingRequest(org.alfresco.query.PagingRequest) CustomModel(org.alfresco.rest.api.model.CustomModel)

Example 2 with CustomModelDefinition

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

the class CustomModelsImpl method createCustomModelImpl.

private CustomModel createCustomModelImpl(CustomModel model, boolean basicModelOnly) {
    M2Model m2Model = null;
    if (basicModelOnly) {
        m2Model = convertToM2Model(model, null, null, null);
    } else {
        m2Model = convertToM2Model(model, model.getTypes(), model.getAspects(), model.getConstraints());
    }
    boolean activate = ModelStatus.ACTIVE.equals(model.getStatus());
    try {
        CustomModelDefinition modelDefinition = customModelService.createCustomModel(m2Model, activate);
        return new CustomModel(modelDefinition);
    } catch (ModelExistsException me) {
        throw new ConstraintViolatedException(me.getMessage());
    } catch (CustomModelConstraintException ncx) {
        throw new ConstraintViolatedException(ncx.getMessage());
    } catch (InvalidCustomModelException iex) {
        throw new InvalidArgumentException(iex.getMessage());
    } catch (Exception e) {
        throw new ApiException("cmm.rest_api.model_invalid", e);
    }
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ModelExistsException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) M2Model(org.alfresco.repo.dictionary.M2Model) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModel(org.alfresco.rest.api.model.CustomModel) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActiveModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException) ModelDoesNotExistException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) CustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException) ModelExistsException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 3 with CustomModelDefinition

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

the class CustomModelsImpl method getCustomModelConstraint.

@Override
public CustomModelConstraint getCustomModelConstraint(String modelName, String constraintName, Parameters parameters) {
    if (constraintName == null) {
        throw new InvalidArgumentException(CONSTRAINT_NAME_NULL_ERR);
    }
    final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    QName constraintQname = QName.createQName(modelDef.getName().getNamespaceURI(), constraintName);
    ConstraintDefinition constraintDef = customModelService.getCustomConstraint(constraintQname);
    if (constraintDef == null) {
        throw new EntityNotFoundException(constraintName);
    }
    return new CustomModelConstraint(constraintDef, dictionaryService);
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 4 with CustomModelDefinition

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);
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 5 with CustomModelDefinition

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

the class CustomModelsImpl method getCustomModelConstraints.

@Override
public CollectionWithPagingInfo<CustomModelConstraint> getCustomModelConstraints(String modelName, Parameters parameters) {
    CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    Collection<ConstraintDefinition> constraintDefinitions = modelDef.getModelDefinedConstraints();
    // TODO Should we support paging?
    Paging paging = Paging.DEFAULT;
    List<CustomModelConstraint> customModelConstraints = convertToCustomModelConstraints(constraintDefinitions);
    return CollectionWithPagingInfo.asPaged(paging, customModelConstraints, false, constraintDefinitions.size());
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Aggregations

CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)10 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)5 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)5 Paging (org.alfresco.rest.framework.resource.parameters.Paging)4 CustomModel (org.alfresco.rest.api.model.CustomModel)3 QName (org.alfresco.service.namespace.QName)3 CustomAspect (org.alfresco.rest.api.model.CustomAspect)2 CustomModelConstraint (org.alfresco.rest.api.model.CustomModelConstraint)2 CustomType (org.alfresco.rest.api.model.CustomType)2 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)2 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)2 ConstraintDefinition (org.alfresco.service.cmr.dictionary.ConstraintDefinition)2 CustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException)2 ActiveModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException)2 CustomModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException)2 InvalidCustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException)2 ModelDoesNotExistException (org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException)2 ModelExistsException (org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException)2