Search in sources :

Example 86 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class RecordsManagementSearchServiceImpl method setReportsJSON.

/**
 * @param reportsJSON
 */
public void setReportsJSON(String reportsJSON) {
    try {
        JSONArray jsonArray = new JSONArray(reportsJSON);
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject report = jsonArray.getJSONObject(i);
            // Get the name
            if (!report.has(SavedSearchDetails.NAME)) {
                throw new AlfrescoRuntimeException("Unable to load report details because name has not been specified. \n" + reportsJSON);
            }
            String name = report.getString(SavedSearchDetails.NAME);
            String translatedName = I18NUtil.getMessage(name);
            if (translatedName != null) {
                name = translatedName;
            }
            // Get the query
            if (!report.has(SavedSearchDetails.SEARCH)) {
                throw new AlfrescoRuntimeException("Unable to load report details because search has not been specified for report " + name + ". \n" + reportsJSON);
            }
            String query = report.getString(SavedSearchDetails.SEARCH);
            // Get the description
            String description = "";
            if (report.has(SavedSearchDetails.DESCRIPTION)) {
                description = report.getString(SavedSearchDetails.DESCRIPTION);
                String translatedDescription = I18NUtil.getMessage(description);
                if (translatedDescription != null) {
                    description = translatedDescription;
                }
            }
            RecordsManagementSearchParameters searchParameters = new RecordsManagementSearchParameters();
            if (report.has("searchparams")) {
                searchParameters = RecordsManagementSearchParameters.createFromJSON(report.getJSONObject("searchparams"), namespaceService);
            }
            // Create the report details and add to list
            ReportDetails reportDetails = new ReportDetails(name, description, query, searchParameters);
            reports.add(reportDetails);
        }
    } catch (JSONException exception) {
        throw new AlfrescoRuntimeException("Unable to load report details.\n" + reportsJSON, exception);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONException(org.json.JSONException)

Example 87 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class SavedSearchDetails method createFromJSON.

/**
 * @param jsonString
 * @return
 */
/*package*/
static SavedSearchDetails createFromJSON(String jsonString, NamespaceService namespaceService, RecordsManagementSearchServiceImpl searchService, NodeRef nodeRef) {
    try {
        JSONObject search = new JSONObject(jsonString);
        // Get the site id
        String siteId = DEFAULT_SITE_ID;
        if (search.has(SITE_ID)) {
            siteId = search.getString(SITE_ID);
        }
        // Get the name
        if (!search.has(NAME)) {
            throw new AlfrescoRuntimeException("Can not create saved search details from json, because required name is not present. " + jsonString);
        }
        String name = search.getString(NAME);
        // Get the description
        String description = "";
        if (search.has(DESCRIPTION)) {
            description = search.getString(DESCRIPTION);
            String translated = I18NUtil.getMessage(description);
            if (translated != null) {
                description = translated;
            }
        }
        // Get the query
        String query = null;
        if (!search.has(SEARCH)) {
            // We are probably dealing with a "old" style saved search
            if (search.has(PARAMS)) {
                String oldParams = search.getString(PARAMS);
                query = SavedSearchDetailsCompatibility.getSearchFromParams(oldParams);
            } else {
                throw new AlfrescoRuntimeException("Can not create saved search details from json, because required search is not present. " + jsonString);
            }
        } else {
            query = search.getString(SEARCH);
        }
        // Get the search parameters
        RecordsManagementSearchParameters searchParameters = new RecordsManagementSearchParameters();
        if (search.has(SEARCHPARAMS)) {
            searchParameters = RecordsManagementSearchParameters.createFromJSON(search.getJSONObject(SEARCHPARAMS), namespaceService);
        } else {
            // See if we are dealing with the old style of saved search
            if (search.has(PARAMS)) {
                String oldParams = search.getString(PARAMS);
                String oldSort = search.getString(SORT);
                searchParameters = SavedSearchDetailsCompatibility.createSearchParameters(oldParams, oldSort, namespaceService);
            }
        }
        // Determine whether the saved query is public or not
        boolean isPublic = true;
        if (search.has(PUBLIC)) {
            isPublic = search.getBoolean(PUBLIC);
        }
        // Determine whether the saved query is a report or not
        boolean isReport = false;
        if (search.has(REPORT)) {
            isReport = search.getBoolean(REPORT);
        }
        // Create the saved search details object
        SavedSearchDetails savedSearchDetails = new SavedSearchDetails(siteId, name, description, query, searchParameters, isPublic, isReport, namespaceService, searchService);
        savedSearchDetails.nodeRef = nodeRef;
        return savedSearchDetails;
    } catch (JSONException exception) {
        throw new AlfrescoRuntimeException("Can not create saved search details from json. " + jsonString, exception);
    }
}
Also used : JSONObject(org.json.JSONObject) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONException(org.json.JSONException)

Example 88 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class FilePlanPermissionServiceImpl method setupRecordCategoryPermissions.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService#setupRecordCategoryPermissions(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public void setupRecordCategoryPermissions(final NodeRef recordCategory) {
    mandatory("recordCategory", recordCategory);
    // assert that we have a record category in our hands
    if (!instanceOf(recordCategory, TYPE_RECORD_CATEGORY)) {
        throw new AlfrescoRuntimeException("Unable to setup record category permissions, because node is not a record category.");
    }
    // setup category permissions
    NodeRef parentNodeRef = nodeService.getPrimaryParent(recordCategory).getParentRef();
    setupPermissions(parentNodeRef, recordCategory);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 89 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class ApplyDodCertModelFixesGet method executeImpl.

@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    LOGGER.info("Applying webscript-based patches to RM custom model in the repo.");
    M2Model customModel = readCustomContentModel();
    if (customModel == null) {
        final String msg = "Custom content model could not be read";
        LOGGER.error(msg);
        throw new AlfrescoRuntimeException(msg);
    }
    String customAspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(namespaceService);
    M2Aspect customAssocsAspect = customModel.getAspect(customAspectName);
    if (customAssocsAspect == null) {
        final String msg = "Unknown aspect: " + customAspectName;
        LOGGER.error(msg);
        throw new AlfrescoRuntimeException(msg);
    }
    // MOB-1573. All custom references should have many-many multiplicity.
    LOGGER.info("MOB-1573. All custom references should have many-many multiplicity.");
    for (M2ClassAssociation classAssoc : customAssocsAspect.getAssociations()) {
        classAssoc.setSourceMany(true);
        classAssoc.setTargetMany(true);
    }
    // MOB-1621. Custom fields should be created as untokenized by default.
    LOGGER.info("MOB-1621. Custom fields should be created as untokenized by default.");
    List<String> allCustomPropertiesAspects = new ArrayList<String>(4);
    allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_SERIES_PROPERTIES);
    allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_CATEGORY_PROPERTIES);
    allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_FOLDER_PROPERTIES);
    allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_PROPERTIES);
    for (String aspectName : allCustomPropertiesAspects) {
        M2Aspect aspectObj = customModel.getAspect(aspectName);
        List<M2Property> customProperties = aspectObj.getProperties();
        for (M2Property propertyObj : customProperties) {
            propertyObj.setIndexed(true);
            propertyObj.setIndexedAtomically(true);
            propertyObj.setStoredInIndex(false);
            propertyObj.setIndexTokenisationMode(IndexTokenisationMode.FALSE);
        }
    }
    writeCustomContentModel(customModel);
    LOGGER.info("Completed application of webscript-based patches to RM custom model in the repo.");
    Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
    model.put("success", true);
    return model;
}
Also used : HashMap(java.util.HashMap) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

Example 90 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class ApplyDodCertModelFixesGet method readCustomContentModel.

private M2Model readCustomContentModel() {
    ContentReader reader = this.contentService.getReader(RM_CUSTOM_MODEL_NODE_REF, ContentModel.TYPE_CONTENT);
    if (!reader.exists()) {
        throw new AlfrescoRuntimeException("RM CustomModel has no content.");
    }
    InputStream contentIn = null;
    M2Model deserializedModel = null;
    try {
        contentIn = reader.getContentInputStream();
        deserializedModel = M2Model.createModel(contentIn);
    } finally {
        try {
            if (contentIn != null) {
                contentIn.close();
            }
        } catch (IOException ignored) {
        // Intentionally empty.`
        }
    }
    return deserializedModel;
}
Also used : InputStream(java.io.InputStream) ContentReader(org.alfresco.service.cmr.repository.ContentReader) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException)

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