mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-1482 (No message is shown when user tries to file Audit Log as Record to File Pan or closed folder)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@70298 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -187,6 +187,8 @@
|
|||||||
<property name="mimetypeService" ref="mimetypeService" />
|
<property name="mimetypeService" ref="mimetypeService" />
|
||||||
<property name="recordsManagementAuditService" ref="RecordsManagementAuditService" />
|
<property name="recordsManagementAuditService" ref="RecordsManagementAuditService" />
|
||||||
<property name="namespaceService" ref="namespaceService" />
|
<property name="namespaceService" ref="namespaceService" />
|
||||||
|
<property name="recordFolderService" ref="RecordFolderService" />
|
||||||
|
<property name="dispositionService" ref="DispositionService" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- REST impl for PUT Audit Log (starting and stopping auditing) -->
|
<!-- REST impl for PUT Audit Log (starting and stopping auditing) -->
|
||||||
|
@@ -19,24 +19,25 @@
|
|||||||
package org.alfresco.module.org_alfresco_module_rm.script;
|
package org.alfresco.module.org_alfresco_module_rm.script;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
import org.alfresco.util.ParameterCheck;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
|
||||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
|
||||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation for Java backed webscript to file an
|
* Implementation for Java backed webscript to file an
|
||||||
@@ -49,105 +50,240 @@ public class AuditLogPost extends BaseAuditRetrievalWebScript
|
|||||||
/** Logger */
|
/** Logger */
|
||||||
private static Log logger = LogFactory.getLog(AuditLogPost.class);
|
private static Log logger = LogFactory.getLog(AuditLogPost.class);
|
||||||
|
|
||||||
|
/** Constants */
|
||||||
protected static final String PARAM_DESTINATION = "destination";
|
protected static final String PARAM_DESTINATION = "destination";
|
||||||
protected static final String RESPONSE_SUCCESS = "success";
|
protected static final String RESPONSE_SUCCESS = "success";
|
||||||
protected static final String RESPONSE_RECORD = "record";
|
protected static final String RESPONSE_RECORD = "record";
|
||||||
protected static final String RESPONSE_RECORD_NAME = "recordName";
|
protected static final String RESPONSE_RECORD_NAME = "recordName";
|
||||||
|
|
||||||
|
/** Record folder service */
|
||||||
|
private RecordFolderService recordFolderService;
|
||||||
|
|
||||||
|
/** Disposition service */
|
||||||
|
private DispositionService dispositionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the record folder service
|
||||||
|
*
|
||||||
|
* @param recordFolderService Record folder service
|
||||||
|
*/
|
||||||
|
public void setRecordFolderService(RecordFolderService recordFolderService)
|
||||||
|
{
|
||||||
|
this.recordFolderService = recordFolderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the disposition service
|
||||||
|
*
|
||||||
|
* @param dispositionService disposition service
|
||||||
|
*/
|
||||||
|
public void setDispositionService(DispositionService dispositionService)
|
||||||
|
{
|
||||||
|
this.dispositionService = dispositionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.repo.web.scripts.content.StreamContent#execute(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.WebScriptResponse)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
|
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// retrieve requested format
|
ParameterCheck.mandatory("req", req);
|
||||||
String format = req.getFormat();
|
ParameterCheck.mandatory("res", res);
|
||||||
|
|
||||||
// construct model for template
|
// build the json object from the request
|
||||||
Status status = new Status();
|
JSONObject json = getJSONObjectFromRequest(req);
|
||||||
Cache cache = new Cache(getDescription().getRequiredCache());
|
|
||||||
Map<String, Object> model = new HashMap<String, Object>();
|
|
||||||
model.put("status", status);
|
|
||||||
model.put("cache", cache);
|
|
||||||
|
|
||||||
// extract the destination parameter, ensure it's present and it is
|
// extract the destination parameter, ensure it's present and it is a record folder and not closed or cut off
|
||||||
// a record folder
|
NodeRef destination = getDestination(json);
|
||||||
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
|
||||||
if (!json.has(PARAM_DESTINATION))
|
// file audit trail as a record
|
||||||
|
NodeRef record = fileAuditTrail(destination, req);
|
||||||
|
|
||||||
|
// create response
|
||||||
|
String response = createResponse(record);
|
||||||
|
|
||||||
|
// write the JSON response
|
||||||
|
writeResponse(res, response);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
status.setCode(HttpServletResponse.SC_BAD_REQUEST,
|
JSONObject json = new JSONObject();
|
||||||
"Mandatory '" + PARAM_DESTINATION + "' parameter has not been supplied");
|
putToJSONObject(json, "message", ex.getMessage());
|
||||||
Map<String, Object> templateModel = createTemplateParameters(req, res, model);
|
writeResponse(res, json.toString());
|
||||||
sendStatus(req, res, status, cache, format, templateModel);
|
}
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to write the response to the web script response
|
||||||
|
*
|
||||||
|
* @param res {@link WebScriptResponse} Web script response
|
||||||
|
* @param reponse {@link String} Response to write
|
||||||
|
* @throws IOException can throw an exception whilst writing the response
|
||||||
|
*/
|
||||||
|
private void writeResponse(WebScriptResponse res, String response) throws IOException
|
||||||
|
{
|
||||||
|
// setup response
|
||||||
|
res.setContentType(MimetypeMap.MIMETYPE_JSON);
|
||||||
|
res.setContentEncoding("UTF-8");
|
||||||
|
res.setHeader("Content-Length", Long.toString(response.length()));
|
||||||
|
|
||||||
|
// write the JSON response
|
||||||
|
res.getWriter().write(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create the response text from the record
|
||||||
|
*
|
||||||
|
* @param record {@link NodeRef} The audit trail as record
|
||||||
|
* @return Response text as {@link String}
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("null")
|
||||||
|
private String createResponse(NodeRef record)
|
||||||
|
{
|
||||||
|
JSONObject responseJSON = new JSONObject();
|
||||||
|
boolean recordExists = record != null;
|
||||||
|
|
||||||
|
putToJSONObject(responseJSON, RESPONSE_SUCCESS, recordExists);
|
||||||
|
|
||||||
|
if (recordExists)
|
||||||
|
{
|
||||||
|
putToJSONObject(responseJSON, RESPONSE_RECORD, record.toString());
|
||||||
|
putToJSONObject(responseJSON, RESPONSE_RECORD_NAME, (String) nodeService.getProperty(record, ContentModel.PROP_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseJSON.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to put a key and a value to a json object.
|
||||||
|
* It handles the {@link JSONException} so that a try/catch
|
||||||
|
* block is not need through out the code
|
||||||
|
*
|
||||||
|
* @param json The json object the key/value write to
|
||||||
|
* @param key The key which will be written to the json object
|
||||||
|
* @param value The value which will be written to the json object
|
||||||
|
*/
|
||||||
|
private void putToJSONObject(JSONObject json, String key, Object value)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
json.put(key, value);
|
||||||
|
}
|
||||||
|
catch (JSONException error)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Error writing the value '" + value + "' of the key '" + key + "' to the json object.", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method which will file the audit trail
|
||||||
|
*
|
||||||
|
* @param destination The destination where the audit trail will be filed
|
||||||
|
* @param req {@link WebScriptRequest} from which additional parameters will be retrieved
|
||||||
|
* @return The {@link NodeRef} of the record
|
||||||
|
*/
|
||||||
|
private NodeRef fileAuditTrail(NodeRef destination, WebScriptRequest req)
|
||||||
|
{
|
||||||
|
|
||||||
|
NodeRef record = rmAuditService.fileAuditTrailAsRecord(parseQueryParameters(req), destination, parseReportFormat(req));
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Filed audit trail as new record: '" + record + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create a json object from the request
|
||||||
|
*
|
||||||
|
* @param req {@link WebScriptRequest} from which the json object will be created
|
||||||
|
* @return Returns a json object containing the request content
|
||||||
|
* @throws IOException can throw an exception whilst getting the content from the request
|
||||||
|
*/
|
||||||
|
private JSONObject getJSONObjectFromRequest(WebScriptRequest req) throws IOException
|
||||||
|
{
|
||||||
|
JSONObject json;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||||
|
}
|
||||||
|
catch (JSONException error)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Error creating json object from request content.", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
String destinationParam = json.getString(PARAM_DESTINATION);
|
|
||||||
if (StringUtils.isBlank(destinationParam))
|
if (StringUtils.isBlank(destinationParam))
|
||||||
{
|
{
|
||||||
status.setCode(HttpServletResponse.SC_BAD_REQUEST,
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
||||||
"Please select a record folder.");
|
"Please select a record folder.");
|
||||||
Map<String, Object> templateModel = createTemplateParameters(req, res, model);
|
|
||||||
sendStatus(req, res, status, cache, format, templateModel);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeRef destination = new NodeRef(destinationParam);
|
NodeRef destination = new NodeRef(destinationParam);
|
||||||
|
if (!nodeService.exists(destination))
|
||||||
if (!this.nodeService.exists(destination))
|
|
||||||
{
|
{
|
||||||
status.setCode(HttpServletResponse.SC_NOT_FOUND,
|
throw new WebScriptException(Status.STATUS_NOT_FOUND,
|
||||||
"Node " + destination.toString() + " does not exist");
|
"Selected node does not exist");
|
||||||
Map<String, Object> templateModel = createTemplateParameters(req, res, model);
|
|
||||||
sendStatus(req, res, status, cache, format, templateModel);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure the node is a filePlan object
|
// ensure the node is a record folder
|
||||||
if (!RecordsManagementModel.TYPE_RECORD_FOLDER.equals(this.nodeService.getType(destination)))
|
if (!RecordsManagementModel.TYPE_RECORD_FOLDER.equals(nodeService.getType(destination)))
|
||||||
{
|
{
|
||||||
status.setCode(HttpServletResponse.SC_BAD_REQUEST,
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
||||||
"Node " + destination.toString() + " is not a record folder");
|
"Selected node is not a record folder");
|
||||||
Map<String, Object> templateModel = createTemplateParameters(req, res, model);
|
}
|
||||||
sendStatus(req, res, status, cache, format, templateModel);
|
|
||||||
return;
|
// 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())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("Filing audit trail as record in record folder: " + destination);
|
logger.debug("Filing audit trail as record in record folder: '" + destination + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the other parameters and get a file containing the audit trail
|
return destination;
|
||||||
NodeRef record = this.rmAuditService.fileAuditTrailAsRecord(parseQueryParameters(req),
|
|
||||||
destination, parseReportFormat(req));
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("Filed audit trail as new record: " + record);
|
|
||||||
}
|
|
||||||
|
|
||||||
// return success flag and record noderef as JSON
|
|
||||||
JSONObject responseJSON = new JSONObject();
|
|
||||||
responseJSON.put(RESPONSE_SUCCESS, (record != null));
|
|
||||||
if (record != null)
|
|
||||||
{
|
|
||||||
responseJSON.put(RESPONSE_RECORD, record.toString());
|
|
||||||
responseJSON.put(RESPONSE_RECORD_NAME,
|
|
||||||
(String)nodeService.getProperty(record, ContentModel.PROP_NAME));
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup response
|
|
||||||
String jsonString = responseJSON.toString();
|
|
||||||
res.setContentType(MimetypeMap.MIMETYPE_JSON);
|
|
||||||
res.setContentEncoding("UTF-8");
|
|
||||||
res.setHeader("Content-Length", Long.toString(jsonString.length()));
|
|
||||||
|
|
||||||
// write the JSON response
|
|
||||||
res.getWriter().write(jsonString);
|
|
||||||
}
|
|
||||||
catch (Throwable e)
|
|
||||||
{
|
|
||||||
throw createStatusException(e, req, res);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user