use of org.alfresco.rest.framework.core.exceptions.ApiException in project alfresco-remote-api by Alfresco.
the class MapBasedQueryWalker method processVariable.
protected void processVariable(String propertyName, String propertyValue, int type) {
String localPropertyName = propertyName.replaceFirst("variables/", "");
Object actualValue = null;
DataTypeDefinition dataTypeDefinition = null;
// variable scope global is default
String scopeDef = "global";
// look for variable scope
if (localPropertyName.contains("local/")) {
scopeDef = "local";
localPropertyName = localPropertyName.replaceFirst("local/", "");
}
if (localPropertyName.contains("global/")) {
localPropertyName = localPropertyName.replaceFirst("global/", "");
}
// look for variable type definition
if ((propertyValue.contains("_") || propertyValue.contains(":")) && propertyValue.contains(" ")) {
int indexOfSpace = propertyValue.indexOf(' ');
if ((propertyValue.contains("_") && indexOfSpace > propertyValue.indexOf("_")) || (propertyValue.contains(":") && indexOfSpace > propertyValue.indexOf(":"))) {
String typeDef = propertyValue.substring(0, indexOfSpace);
try {
QName dataType = QName.createQName(typeDef.replace('_', ':'), namespaceService);
dataTypeDefinition = dictionaryService.getDataType(dataType);
propertyValue = propertyValue.substring(indexOfSpace + 1);
} catch (Exception e) {
throw new ApiException("Error translating propertyName " + propertyName + " with value " + propertyValue);
}
}
}
if (dataTypeDefinition != null && "java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName())) {
// fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
actualValue = ISO8601DateFormat.parse(propertyValue);
} else if (dataTypeDefinition != null) {
actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, propertyValue);
} else {
actualValue = propertyValue;
}
variableProperties.add(new QueryVariableHolder(localPropertyName, type, actualValue, scopeDef));
}
use of org.alfresco.rest.framework.core.exceptions.ApiException 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);
}
}
use of org.alfresco.rest.framework.core.exceptions.ApiException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method createDownload.
@Override
public CustomModelDownload createDownload(String modelName, Parameters parameters) {
// Check the current user is authorised to export the model
validateCurrentUser();
if (modelName == null) {
throw new InvalidArgumentException(MODEL_NAME_NULL_ERR);
}
String propName = parameters.getParameter(PARAM_WITH_EXT_MODULE);
boolean withForm = Boolean.valueOf(propName);
try {
NodeRef nodeRef = customModelService.createDownloadNode(modelName, withForm);
return new CustomModelDownload(nodeRef);
} catch (Exception ex) {
String errorMsg = "cmm.rest_api.model_download_failure";
if (ex.getMessage() != null) {
errorMsg = ex.getMessage();
}
throw new ApiException(errorMsg, ex);
}
}
use of org.alfresco.rest.framework.core.exceptions.ApiException in project alfresco-remote-api by Alfresco.
the class DeletedNodesImpl method restoreArchivedNode.
@Override
public Node restoreArchivedNode(String archivedId, NodeTargetAssoc nodeTargetAssoc) {
// First check the node is valid and has been archived.
NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
RestoreNodeReport restored = null;
if (nodeTargetAssoc != null) {
NodeRef targetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeTargetAssoc.getTargetParentId());
QName assocType = nodes.getAssocType(nodeTargetAssoc.getAssocType());
restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef, targetNodeRef, assocType, null);
} else {
restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef);
}
switch(restored.getStatus()) {
case SUCCESS:
return nodes.getFolderOrDocumentFullInfo(restored.getRestoredNodeRef(), null, null, null, null);
case FAILURE_PERMISSION:
throw new PermissionDeniedException();
case FAILURE_INTEGRITY:
throw new IntegrityException("Restore failed due to an integrity error", null);
case FAILURE_DUPLICATE_CHILD_NODE_NAME:
throw new ConstraintViolatedException("Name already exists in target");
case FAILURE_INVALID_ARCHIVE_NODE:
throw new EntityNotFoundException(archivedId);
case FAILURE_INVALID_PARENT:
throw new NotFoundException("Invalid parent id " + restored.getTargetParentNodeRef());
default:
throw new ApiException("Unable to restore node " + archivedId);
}
}
use of org.alfresco.rest.framework.core.exceptions.ApiException 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);
}
}
Aggregations