mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Rename Configuration to ClassificationServiceDAO.
Also formatting changes as per code review comments. +review RM-5 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@100687 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -16,78 +16,77 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.classification;
|
||||
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* This class is a POJO data type for a classification reason.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 3.0
|
||||
*/
|
||||
public final class ClassificationReason implements Serializable {
|
||||
private static final long serialVersionUID = 4876939094239038838L;
|
||||
private final String id;
|
||||
private final String displayLabelKey;
|
||||
public final class ClassificationReason implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 4876939094239038838L;
|
||||
private final String id;
|
||||
private final String displayLabelKey;
|
||||
|
||||
/**
|
||||
* Constructor to create a classification reason.
|
||||
*
|
||||
* @param id
|
||||
* The unique identifier that represents this classification
|
||||
* reason.
|
||||
* @param displayLabelKey
|
||||
* The I18N key for the display label for the reason.
|
||||
*/
|
||||
public ClassificationReason(final String id, final String displayLabelKey) {
|
||||
if (id == null || id.trim().equals("")) {
|
||||
throw new IllegalArgumentException("Illegal id: '" + id + "'");
|
||||
}
|
||||
this.id = id;
|
||||
this.displayLabelKey = displayLabelKey;
|
||||
}
|
||||
/**
|
||||
* Constructor to create a classification reason.
|
||||
*
|
||||
* @param id The unique identifier that represents this classification reason.
|
||||
* @param displayLabelKey The I18N key for the display label for the reason.
|
||||
*/
|
||||
public ClassificationReason(final String id, final String displayLabelKey)
|
||||
{
|
||||
if (id == null || id.trim().equals("")) { throw new IllegalArgumentException("Illegal id: '" + id + "'"); }
|
||||
this.id = id;
|
||||
this.displayLabelKey = displayLabelKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique identifier that represents this classification reason.
|
||||
*/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
/**
|
||||
* Returns the unique identifier that represents this classification reason.
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the localised (current locale) display label for this
|
||||
* classification reason.
|
||||
*/
|
||||
public String getDisplayLabel() {
|
||||
return I18NUtil.getMessage(displayLabelKey);
|
||||
}
|
||||
/**
|
||||
* Returns the localised (current locale) display label for this classification reason.
|
||||
*/
|
||||
public String getDisplayLabel()
|
||||
{
|
||||
return I18NUtil.getMessage(displayLabelKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(ClassificationReason.class.getSimpleName()).append(":")
|
||||
.append(id);
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(ClassificationReason.class.getSimpleName()).append(":").append(id);
|
||||
|
||||
return msg.toString();
|
||||
}
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ClassificationReason that = (ClassificationReason) o;
|
||||
ClassificationReason that = (ClassificationReason) o;
|
||||
|
||||
return this.id.equals(that.id);
|
||||
}
|
||||
return this.id.equals(that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return id.hashCode();
|
||||
}
|
||||
}
|
||||
|
@@ -38,12 +38,12 @@ import org.json.JSONTokener;
|
||||
* @author Neil Mc Erlean
|
||||
* @since 3.0
|
||||
*/
|
||||
class Configuration
|
||||
class ClassificationServiceDAO
|
||||
{
|
||||
public final String levelConfigLocation;
|
||||
public final String reasonConfigLocation;
|
||||
|
||||
public Configuration(String levelConfigLocation, String reasonConfigLocation)
|
||||
public ClassificationServiceDAO(String levelConfigLocation, String reasonConfigLocation)
|
||||
{
|
||||
this.levelConfigLocation = levelConfigLocation;
|
||||
this.reasonConfigLocation = reasonConfigLocation;
|
||||
@@ -88,7 +88,8 @@ class Configuration
|
||||
*
|
||||
* @return the configured classification reasons in descending order, or an empty list if there are none.
|
||||
*/
|
||||
public List<ClassificationReason> getConfiguredReasons() {
|
||||
public List<ClassificationReason> getConfiguredReasons()
|
||||
{
|
||||
List<ClassificationReason> result;
|
||||
try (final InputStream in = this.getClass().getResourceAsStream(reasonConfigLocation))
|
||||
{
|
||||
@@ -114,5 +115,5 @@ class Configuration
|
||||
throw new MalformedConfiguration("Could not read classification reason configuration", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -55,22 +55,22 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
/** The classification reasons currently configured in this server. */
|
||||
private List<ClassificationReason> configuredReasons;
|
||||
|
||||
private final Configuration config;
|
||||
private final ClassificationServiceDAO classificationServiceDao;
|
||||
|
||||
public ClassificationServiceImpl()
|
||||
{
|
||||
this.config = new Configuration(DEFAULT_LEVELS_FILE, DEFAULT_REASONS_FILE);
|
||||
this.classificationServiceDao = new ClassificationServiceDAO(DEFAULT_LEVELS_FILE, DEFAULT_REASONS_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Package protected constructor, primarily for unit testing purposes.
|
||||
*
|
||||
* @param config The object from which configuration options will be read.
|
||||
* @param classificationServiceDao The object from which configuration options will be read.
|
||||
* @param logger The class logger (note - this will be set statically).
|
||||
*/
|
||||
ClassificationServiceImpl(Configuration config, Logger logger)
|
||||
ClassificationServiceImpl(ClassificationServiceDAO classificationServiceDao, Logger logger)
|
||||
{
|
||||
this.config = config;
|
||||
this.classificationServiceDao = classificationServiceDao;
|
||||
ClassificationServiceImpl.logger = logger;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
{
|
||||
throw new MissingConfiguration("Classification level configuration is missing.");
|
||||
}
|
||||
else if ( !configurationLevels.equals(allPersistedLevels))
|
||||
else if (!configurationLevels.equals(allPersistedLevels))
|
||||
{
|
||||
attributeService.setAttribute((Serializable) configurationLevels, LEVELS_KEY);
|
||||
this.configuredLevels = configurationLevels;
|
||||
@@ -100,7 +100,8 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
}
|
||||
}
|
||||
|
||||
void initConfiguredClassificationReasons() {
|
||||
void initConfiguredClassificationReasons()
|
||||
{
|
||||
final List<ClassificationReason> persistedReasons = getPersistedReasons();
|
||||
final List<ClassificationReason> classpathReasons = getConfigurationReasons();
|
||||
|
||||
@@ -121,8 +122,8 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
{
|
||||
if (isEmpty(classpathReasons) || !classpathReasons.equals(persistedReasons))
|
||||
{
|
||||
logger.warn("Classification reasons configured in classpath do not match those stored in Alfresco." +
|
||||
"Alfresco will use the unchanged values stored in the database.");
|
||||
logger.warn("Classification reasons configured in classpath do not match those stored in Alfresco."
|
||||
+ "Alfresco will use the unchanged values stored in the database.");
|
||||
// RM-2073 says that we should log a warning and proceed normally.
|
||||
}
|
||||
this.configuredReasons = persistedReasons;
|
||||
@@ -143,7 +144,8 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
* Gets the list (in descending order) of classification levels - as persisted in the system.
|
||||
* @return the list of classification levels if they have been persisted, else {@code null}.
|
||||
*/
|
||||
List<ClassificationLevel> getPersistedLevels() {
|
||||
List<ClassificationLevel> getPersistedLevels()
|
||||
{
|
||||
return authenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork<List<ClassificationLevel>>()
|
||||
{
|
||||
@Override
|
||||
@@ -158,14 +160,15 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
/** Gets the list (in descending order) of classification levels - as defined in the system configuration. */
|
||||
List<ClassificationLevel> getConfigurationLevels()
|
||||
{
|
||||
return config.getConfiguredLevels();
|
||||
return classificationServiceDao.getConfiguredLevels();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of classification reasons as persisted in the system.
|
||||
* @return the list of classification reasons if they have been persisted, else {@code null}.
|
||||
*/
|
||||
List<ClassificationReason> getPersistedReasons() {
|
||||
List<ClassificationReason> getPersistedReasons()
|
||||
{
|
||||
return authenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork<List<ClassificationReason>>()
|
||||
{
|
||||
@Override
|
||||
@@ -180,7 +183,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
/** Gets the list of classification reasons - as defined and ordered in the system configuration. */
|
||||
List<ClassificationReason> getConfigurationReasons()
|
||||
{
|
||||
return config.getConfiguredReasons();
|
||||
return classificationServiceDao.getConfiguredReasons();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user