mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
updated serialId in new RecordMissingMetadataException
This commit is contained in:
@@ -139,6 +139,16 @@ public class RecordsAPI extends RMModelRequest
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* see {@link #completeRecord(String, String)
|
||||
*/
|
||||
public Record completeRecord(String recordId) throws Exception
|
||||
{
|
||||
mandatoryString("recordId", recordId);
|
||||
|
||||
return completeRecord(recordId, EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete the record recordId
|
||||
*
|
||||
|
@@ -27,10 +27,8 @@
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.action.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordMissingMetadataException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.repo.node.integrity.IntegrityException;
|
||||
@@ -74,27 +72,15 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
|
||||
{
|
||||
recordService.complete(actionedUponNodeRef);
|
||||
}
|
||||
catch (IntegrityException e)
|
||||
{
|
||||
Map<String, String> errorMap = getErrorMessageMap();
|
||||
if (e.getMsgId().equals(errorMap.get(MISSING_PROPERTIES)))
|
||||
catch (RecordMissingMetadataException e)
|
||||
{
|
||||
action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, MISSING_PROPERTIES);
|
||||
}
|
||||
catch (IntegrityException e)
|
||||
{
|
||||
// IntegrityException is deliberately ignored here, there should be no action taken
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: needs to be properties file
|
||||
* Temporary Helper method to get the map of complete record error message keys with associated message text
|
||||
* @return errorMap
|
||||
*/
|
||||
private Map<String, String> getErrorMessageMap() {
|
||||
Map<String, String> errorMap = new HashMap<>();
|
||||
errorMap.put("missingProperties", "The record has missing mandatory properties.");
|
||||
errorMap.put("alreadyCompleted", "The record is already completed.");
|
||||
errorMap.put("unsuitableNode", "The node is not a record or the record does not exist or is frozen.");
|
||||
return errorMap;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.record;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
|
||||
/**
|
||||
* Record missing metadata exception class
|
||||
*
|
||||
* @author Sara Aspery
|
||||
* @since 2.6
|
||||
*/
|
||||
public class RecordMissingMetadataException extends AlfrescoRuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 3437687270967611234L;
|
||||
|
||||
public RecordMissingMetadataException(String msgId, Throwable cause)
|
||||
{
|
||||
super(msgId, cause);
|
||||
}
|
||||
|
||||
public RecordMissingMetadataException(String msgId, Object[] msgParams, Throwable cause)
|
||||
{
|
||||
super(msgId, msgParams, cause);
|
||||
}
|
||||
|
||||
public RecordMissingMetadataException(String msgId, Object[] msgParams)
|
||||
{
|
||||
super(msgId, msgParams);
|
||||
}
|
||||
|
||||
public RecordMissingMetadataException(String msgId)
|
||||
{
|
||||
super(msgId);
|
||||
}
|
||||
}
|
@@ -1992,7 +1992,8 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} finally
|
||||
}
|
||||
finally
|
||||
{
|
||||
enablePropertyEditableCheck();
|
||||
}
|
||||
@@ -2005,10 +2006,29 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
* @throws Exception if node not valid for completion
|
||||
*/
|
||||
private void validateForCompletion(NodeRef nodeRef) {
|
||||
if (nodeService.exists(nodeRef) && isRecord(nodeRef) && !freezeService.isFrozen(nodeRef))
|
||||
if (!nodeService.exists(nodeRef))
|
||||
{
|
||||
if (!isDeclared(nodeRef))
|
||||
logError(nodeRef);
|
||||
throw new IntegrityException("The record does not exist.", null);
|
||||
}
|
||||
|
||||
if (!isRecord(nodeRef))
|
||||
{
|
||||
logError(nodeRef);
|
||||
throw new IntegrityException("The node is not a record.", null);
|
||||
}
|
||||
|
||||
if (freezeService.isFrozen(nodeRef))
|
||||
{
|
||||
logError(nodeRef);
|
||||
throw new IntegrityException("The record is frozen.", null);
|
||||
}
|
||||
|
||||
if (isDeclared(nodeRef))
|
||||
{
|
||||
throw new IntegrityException("The record is already completed.", null);
|
||||
}
|
||||
|
||||
// if the record is newly created make sure the record identifier is set before completing the record
|
||||
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS);
|
||||
if (newRecords.contains(nodeRef))
|
||||
@@ -2016,45 +2036,10 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
generateRecordIdentifier(nodeService, identifierService, nodeRef);
|
||||
}
|
||||
|
||||
// Validate that all mandatory properties, if any, are present
|
||||
List<String> missingProperties = new ArrayList<>(5);
|
||||
// Aspect not already defined - check mandatory properties then add
|
||||
if (checkMandatoryPropertiesEnabled && !mandatoryPropertiesSet(nodeRef, missingProperties))
|
||||
{
|
||||
LOGGER.debug(buildMissingPropertiesErrorString(missingProperties));
|
||||
throw new IntegrityException("The record has missing mandatory properties.", null);
|
||||
}
|
||||
} else
|
||||
{
|
||||
throw new IntegrityException("The record is already completed.", null);
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (LOGGER.isWarnEnabled())
|
||||
{
|
||||
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
|
||||
}
|
||||
throw new IntegrityException("The node is not a record or the record does not exist or is frozen.", null);
|
||||
}
|
||||
}
|
||||
private String buildMissingPropertiesErrorString(List<String> missingProperties)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(255);
|
||||
builder.append(I18NUtil.getMessage(MSG_NO_DECLARE_MAND_PROP));
|
||||
builder.append(" ");
|
||||
for (String missingProperty : missingProperties)
|
||||
{
|
||||
builder.append(missingProperty).append(", ");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to check whether all the mandatory properties of the node have been set
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
* @return boolean true if all mandatory properties are set, false otherwise
|
||||
*/
|
||||
private boolean mandatoryPropertiesSet(final NodeRef nodeRef, final List<String> missingProperties)
|
||||
if (checkMandatoryPropertiesEnabled)
|
||||
{
|
||||
Map<QName, Serializable> nodeRefProps = nodeService.getProperties(nodeRef);
|
||||
QName nodeRefType = nodeService.getType(nodeRef);
|
||||
@@ -2076,7 +2061,42 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
AspectDefinition aspectDef = dictionaryService.getAspect(customAspect);
|
||||
checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
|
||||
|
||||
return missingProperties.isEmpty();
|
||||
if (!missingProperties.isEmpty())
|
||||
{
|
||||
LOGGER.debug(buildMissingPropertiesErrorString(missingProperties));
|
||||
throw new RecordMissingMetadataException("The record has missing mandatory properties.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to log a warning to the log file
|
||||
*
|
||||
* @param nodeRef node for which error occurred
|
||||
*/
|
||||
private void logError(NodeRef nodeRef) {
|
||||
if (LOGGER.isWarnEnabled())
|
||||
{
|
||||
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to build single string containing list of missing properties
|
||||
*
|
||||
* @param missingProperties list of missing properties
|
||||
* @return String of missing properties
|
||||
*/
|
||||
private String buildMissingPropertiesErrorString(List<String> missingProperties)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(255);
|
||||
builder.append(I18NUtil.getMessage(MSG_NO_DECLARE_MAND_PROP));
|
||||
builder.append(" ");
|
||||
for (String missingProperty : missingProperties)
|
||||
{
|
||||
builder.append(missingProperty).append(", ");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -31,6 +31,7 @@ import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.c
|
||||
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordMissingMetadataException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.repo.activities.ActivityType;
|
||||
import org.alfresco.repo.node.integrity.IntegrityException;
|
||||
@@ -241,7 +242,14 @@ public class RecordsEntityResource implements BinaryResourceAction.Read,
|
||||
NodeRef record = apiUtils.validateRecord(recordId);
|
||||
|
||||
// Complete the record
|
||||
try
|
||||
{
|
||||
recordService.complete(record);
|
||||
}
|
||||
catch (RecordMissingMetadataException e)
|
||||
{
|
||||
throw new IntegrityException("The record has missing mandatory properties.", null);
|
||||
}
|
||||
|
||||
// return record state
|
||||
FileInfo info = fileFolderService.getFileInfo(record);
|
||||
|
Reference in New Issue
Block a user