Search in sources :

Example 91 with AlfrescoRuntimeException

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONException(org.json.JSONException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 92 with AlfrescoRuntimeException

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 93 with AlfrescoRuntimeException

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;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) JSONException(org.json.JSONException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONObject(org.json.JSONObject) IOException(java.io.IOException)

Example 94 with AlfrescoRuntimeException

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)));
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ExitableDirectoryReader(org.apache.lucene.index.ExitableDirectoryReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONTokener(org.json.JSONTokener) ContentStream(org.apache.solr.common.util.ContentStream) JSONObject(org.json.JSONObject) BufferedReader(java.io.BufferedReader) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONObject(org.json.JSONObject)

Example 95 with AlfrescoRuntimeException

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();
    }
}
Also used : M2Namespace(org.alfresco.repo.dictionary.M2Namespace) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) M2Model(org.alfresco.repo.dictionary.M2Model) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AuthenticationException(org.alfresco.httpclient.AuthenticationException) JSONException(org.json.JSONException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileFilter(java.io.FileFilter) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)197 NodeRef (org.alfresco.service.cmr.repository.NodeRef)79 QName (org.alfresco.service.namespace.QName)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)32 ArrayList (java.util.ArrayList)31 JSONException (org.json.JSONException)23 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Serializable (java.io.Serializable)20 M2Model (org.alfresco.repo.dictionary.M2Model)18 JSONObject (org.json.JSONObject)15 Date (java.util.Date)14 Map (java.util.Map)12 FacesContext (javax.faces.context.FacesContext)12 InputStream (java.io.InputStream)10 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)10 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)10 JSONArray (org.json.JSONArray)10 List (java.util.List)8 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)8