use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class AuditLogPost method getDestination.
/**
* Helper method to get the destination from the json object
*
* @param json The json object which was created from the request content
* @return {@link NodeRef} The destination of the audit log
*/
private NodeRef getDestination(JSONObject json) {
if (!json.has(PARAM_DESTINATION)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory parameter '" + PARAM_DESTINATION + "' has not been supplied.");
}
String destinationParam;
try {
destinationParam = json.getString(PARAM_DESTINATION);
} catch (JSONException error) {
throw new AlfrescoRuntimeException("Error extracting 'destination' from parameter.", error);
}
if (StringUtils.isBlank(destinationParam)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Please select a record folder.");
}
NodeRef destination = new NodeRef(destinationParam);
if (!nodeService.exists(destination)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Selected node does not exist");
}
// ensure the node is a record folder
if (!RecordsManagementModel.TYPE_RECORD_FOLDER.equals(nodeService.getType(destination))) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Selected node is not a record folder");
}
// ensure the record folder is not closed
if (recordFolderService.isRecordFolderClosed(destination)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Cannot file into a closed folder.");
}
// ensure the record folder is not cut off
if (dispositionService.isDisposableItemCutoff(destination)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Cannot file into a cut off folder.");
}
if (logger.isDebugEnabled()) {
logger.debug("Filing audit trail as record in record folder: '" + destination + "'.");
}
return destination;
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class RecordableVersionServiceImpl method getVersionRecord.
/**
* @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#getVersionRecord(org.alfresco.service.cmr.version.Version)
*/
@Override
public NodeRef getVersionRecord(Version version) {
NodeRef result = null;
NodeRef versionNodeRef = getVersionNodeRef(version);
if (dbNodeService.hasAspect(versionNodeRef, RecordableVersionModel.ASPECT_RECORDED_VERSION)) {
// get the version record
result = (NodeRef) dbNodeService.getProperty(versionNodeRef, RecordableVersionModel.PROP_RECORD_NODE_REF);
// check that the version record exists
if (result != null && !dbNodeService.exists(result)) {
throw new AlfrescoRuntimeException("Version record node doesn't exist. Indicates version has not been updated " + "when associated version record was deleted. " + "(nodeRef=" + result.toString() + ")");
}
}
return result;
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class EmailMapPost method executeImpl.
/**
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>(1);
try {
// Get the data from the content
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// Add custom mapping
customEmailMappingService.addCustomMapping(json.getString("from"), json.getString("to"));
// Add the lists of custom mappings to the model
model.put("emailmap", customEmailMappingService.getCustomMappings());
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
} catch (AlfrescoRuntimeException are) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, are.getMessage(), are);
}
return model;
}
use of org.alfresco.error.AlfrescoRuntimeException in project SearchServices by Alfresco.
the class AlfrescoSearchHandler method readJsonIntoContent.
private void readJsonIntoContent(SolrQueryRequest req) throws IOException {
SolrParams solrParams = req.getParams();
String jsonFacet = solrParams.get("json.facet");
if (jsonFacet != null) {
Object o = ObjectBuilder.fromJSON(jsonFacet);
Map<String, Object> json = new HashMap();
json.put("facet", o);
req.setJSON(json);
}
Iterable<ContentStream> streams = req.getContentStreams();
JSONObject json = (JSONObject) req.getContext().get(AbstractQParser.ALFRESCO_JSON);
if (json == null) {
if (streams != null) {
try {
Reader reader = null;
for (ContentStream stream : streams) {
reader = new BufferedReader(new InputStreamReader(stream.getStream(), "UTF-8"));
}
// SimpleJSON ContentHandler
if (reader != null) {
json = new JSONObject(new JSONTokener(reader));
req.getContext().put(AbstractQParser.ALFRESCO_JSON, json);
}
} catch (JSONException e) {
// This is expected when there is no json element to the
// request
} catch (IOException e) {
throw new AlfrescoRuntimeException("IO Error parsing query parameters", e);
}
} else if (req.getParams().get(AbstractQParser.ALFRESCO_JSON) != null) {
// json is in the params.
req.getContext().put(AbstractQParser.ALFRESCO_JSON, new JSONObject(req.getParams().get(AbstractQParser.ALFRESCO_JSON)));
}
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project SearchServices by Alfresco.
the class ModelTracker method loadPersistedModels.
/**
*/
private void loadPersistedModels() {
HashMap<String, M2Model> modelMap = new HashMap<String, M2Model>();
if (alfrescoModelDir.exists() && alfrescoModelDir.isDirectory()) {
// A filter for XML files
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".xml");
}
};
// List XML files
for (File file : alfrescoModelDir.listFiles(filter)) {
InputStream modelStream = null;
M2Model model;
try {
modelStream = new FileInputStream(file);
model = M2Model.createModel(modelStream);
} catch (IOException e) {
throw new AlfrescoRuntimeException("File not found: " + file, e);
} finally {
if (modelStream != null) {
try {
modelStream.close();
} catch (Exception e) {
}
}
}
// Model successfully loaded
for (M2Namespace namespace : model.getNamespaces()) {
modelMap.put(namespace.getUri(), model);
}
}
}
// Load the models ensuring that they are loaded in the correct order
HashSet<String> loadedModels = new HashSet<String>();
for (M2Model model : modelMap.values()) {
loadModel(modelMap, loadedModels, model);
}
if (modelMap.size() > 0) {
AlfrescoSolrDataModel.getInstance().afterInitModels();
}
}
Aggregations