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);
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations