use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class ResultMapper method getNode.
/**
* Builds a node representation based on a ResultSetRow;
* @param searchRequestContext
* @param aRow
* @param params
* @param mapUserInfo
* @param isHistory
* @return Node
*/
public Node getNode(ResultSetRow aRow, Params params, Map<String, UserInfo> mapUserInfo, boolean isHistory) {
String nodeStore = storeMapper.getStore(aRow.getNodeRef());
if (isHistory)
nodeStore = HISTORY;
Node aNode = null;
switch(nodeStore) {
case LIVE_NODES:
aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
break;
case HISTORY:
aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
break;
case VERSIONS:
Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(aRow.getNodeRef());
NodeRef frozenNodeRef = ((NodeRef) properties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF));
String versionLabelId = (String) properties.get(Version2Model.PROP_QNAME_VERSION_LABEL);
Version v = null;
try {
if (frozenNodeRef != null && versionLabelId != null) {
v = nodeVersions.findVersion(frozenNodeRef.getId(), versionLabelId);
aNode = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, params.getInclude(), mapUserInfo);
}
} catch (EntityNotFoundException | InvalidNodeRefException e) {
// Solr says there is a node but we can't find it
logger.debug("Failed to find a versioned node with id of " + frozenNodeRef + " this is probably because the original node has been deleted.");
}
if (v != null && aNode != null) {
nodeVersions.mapVersionInfo(v, aNode, aRow.getNodeRef());
aNode.setNodeId(frozenNodeRef.getId());
aNode.setVersionLabel(versionLabelId);
}
break;
case DELETED:
try {
aNode = deletedNodes.getDeletedNode(aRow.getNodeRef().getId(), params, false, mapUserInfo);
} catch (EntityNotFoundException enfe) {
// Solr says there is a deleted node but we can't find it, we want the rest of the search to return so lets ignore it.
logger.debug("Failed to find a deleted node with id of " + aRow.getNodeRef().getId());
}
break;
}
if (aNode != null) {
aNode.setLocation(nodeStore);
}
return aNode;
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException 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.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method mergeProperties.
private void mergeProperties(AbstractClassModel existingDetails, AbstractClassModel newDetails, Parameters parameters, boolean isModelActive) {
validateList(newDetails.getProperties(), "cmm.rest_api.properties_empty_null");
// Transform existing properties into a map
Map<String, CustomModelProperty> existingProperties = transformToMap(existingDetails.getProperties(), toNameFunction());
// Transform new properties into a map
Map<String, CustomModelProperty> newProperties = transformToMap(newDetails.getProperties(), toNameFunction());
String propName = parameters.getParameter(PARAM_UPDATE_PROP);
// (propName == null) => property create request
if (propName == null) {
// As this is a create request, check for duplicate properties
for (String name : newProperties.keySet()) {
if (existingProperties.containsKey(name)) {
throw new ConstraintViolatedException(I18NUtil.getMessage("cmm.rest_api.property_create_name_already_in_use", name));
}
}
} else {
// Update request
CustomModelProperty existingProp = existingProperties.get(propName);
if (existingProp == null) {
throw new EntityNotFoundException(propName);
}
CustomModelProperty modifiedProp = newProperties.get(propName);
if (modifiedProp == null) {
throw new InvalidArgumentException("cmm.rest_api.property_update_prop_not_found", new Object[] { propName });
}
existingProp.setTitle(modifiedProp.getTitle());
existingProp.setDescription(modifiedProp.getDescription());
existingProp.setDefaultValue(modifiedProp.getDefaultValue());
existingProp.setConstraintRefs(modifiedProp.getConstraintRefs());
existingProp.setConstraints(modifiedProp.getConstraints());
if (isModelActive) {
validateActivePropertyUpdate(existingProp, modifiedProp);
}
existingProp.setDataType(modifiedProp.getDataType());
existingProp.setMandatory(modifiedProp.isMandatory());
existingProp.setMandatoryEnforced(modifiedProp.isMandatoryEnforced());
existingProp.setMultiValued(modifiedProp.isMultiValued());
}
// Override properties
existingProperties.putAll(newProperties);
existingDetails.setProperties(new ArrayList<>(existingProperties.values()));
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method deleteCustomType.
@Override
public void deleteCustomType(String modelName, String typeName) {
// Check the current user is authorised to delete the custom model's type
validateCurrentUser();
if (typeName == null) {
throw new InvalidArgumentException(TYPE_NAME_NULL_ERR);
}
ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
if (existingModelDetails.isActive()) {
throw new ConstraintViolatedException("cmm.rest_api.type_cannot_delete");
}
Map<String, CustomType> allTypes = transformToMap(existingModelDetails.getTypes(), toNameFunction());
CustomType typeToBeDeleted = allTypes.get(typeName);
if (typeToBeDeleted == null) {
throw new EntityNotFoundException(typeName);
}
// Validate type's dependency
validateTypeAspectDelete(allTypes.values(), typeToBeDeleted.getPrefixedName());
// Remove the validated type
allTypes.remove(typeName);
existingModelDetails.setTypes(new ArrayList<>(allTypes.values()));
updateModel(existingModelDetails, "cmm.rest_api.type_delete_failure");
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class NodesImpl method validateNode.
@Override
public NodeRef validateNode(StoreRef storeRef, String nodeId) {
String versionLabel = null;
int idx = nodeId.indexOf(";");
if (idx != -1) {
versionLabel = nodeId.substring(idx + 1);
nodeId = nodeId.substring(0, idx);
if (versionLabel.equals("pwc")) {
// TODO correct exception?
throw new EntityNotFoundException(nodeId);
}
}
NodeRef nodeRef = new NodeRef(storeRef, nodeId);
return validateNode(nodeRef);
}
Aggregations