From 93e343877e31c405a4b10496e98ca206ed71fbec Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Wed, 12 Jun 2013 20:00:49 +0000 Subject: [PATCH] RM-736 (DOD Recert: Bugs on the "List of Values" page) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/DODRECERT@50975 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../caveat/ScriptConstraint.java | 93 ++++++++++--------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/ScriptConstraint.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/ScriptConstraint.java index 2c3598d20d..4e9dec35d1 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/ScriptConstraint.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/ScriptConstraint.java @@ -28,29 +28,30 @@ import java.util.List; import java.util.Set; import org.alfresco.service.cmr.security.AuthorityService; +import org.apache.commons.lang.StringUtils; import org.json.JSONArray; import org.json.JSONObject; public class ScriptConstraint implements Serializable { /** - * + * */ private static final long serialVersionUID = 1L; private RMConstraintInfo info; - + private RMCaveatConfigService rmCaveatconfigService; - + private AuthorityService authorityService; - + ScriptConstraint(RMConstraintInfo info, RMCaveatConfigService rmCaveatconfigService, AuthorityService authorityService) { this.info = info; - this.rmCaveatconfigService = rmCaveatconfigService; + this.rmCaveatconfigService = rmCaveatconfigService; this.authorityService = authorityService; } - + public void setTitle(String title) { info.setTitle(title); @@ -63,49 +64,49 @@ public class ScriptConstraint implements Serializable { info.setName(name); } - + public String getName() { String xxx = info.getName().replace(":", "_"); return xxx; } - + public boolean isCaseSensitive() { return info.isCaseSensitive(); } - + public String[] getAllowedValues() { return info.getAllowedValues(); } - + public ScriptConstraintAuthority[] getAuthorities() { Map> values = rmCaveatconfigService.getListDetails(info.getName()); - + if (values == null) { return new ScriptConstraintAuthority[0]; } - + // Here with some data to return Set authorities = values.keySet(); - + ArrayList constraints = new ArrayList(values.size()); for(String authority : authorities) { ScriptConstraintAuthority constraint = new ScriptConstraintAuthority(); constraint.setAuthorityName(authority); constraint.setValues(values.get(authority)); - constraints.add(constraint); + constraints.add(constraint); } - + ScriptConstraintAuthority[] retVal = constraints.toArray(new ScriptConstraintAuthority[constraints.size()]); - - return retVal; + + return retVal; } - + /** * updateTitle */ @@ -114,7 +115,7 @@ public class ScriptConstraint implements Serializable info.setTitle(newTitle); rmCaveatconfigService.updateRMConstraintTitle(info.getName(), newTitle) ; } - + /** * updateAllowedValues */ @@ -123,7 +124,7 @@ public class ScriptConstraint implements Serializable info.setAllowedValues(allowedValues); rmCaveatconfigService.updateRMConstraintAllowedValues(info.getName(), allowedValues); } - + /** * Update a value * @param values @@ -133,7 +134,7 @@ public class ScriptConstraint implements Serializable { for(int i = 0; i < bodge.length(); i++) { - + JSONObject obj = bodge.getJSONObject(i); String value = obj.getString("value"); JSONArray authorities = obj.getJSONArray("authorities"); @@ -142,10 +143,10 @@ public class ScriptConstraint implements Serializable { aList.add(authorities.getString(j)); } - rmCaveatconfigService.updateRMConstraintListValue(info.getName(), value, aList); - } + rmCaveatconfigService.updateRMConstraintListValue(info.getName(), value, aList); + } } - + /** * Update a value * @param values @@ -154,27 +155,27 @@ public class ScriptConstraint implements Serializable public void updateValues(String value, String[] authorities) { List list = Arrays.asList(authorities); - rmCaveatconfigService.updateRMConstraintListValue(info.getName(), value, list); + rmCaveatconfigService.updateRMConstraintListValue(info.getName(), value, list); } - + /** * Cascade delete an authority * @param authority */ public void deleteAuthority(String authority) { - + } - + /** * Cascade delete a value * @param value */ public void deleteValue(String value) { - + } - + /** * Get a single value @@ -184,7 +185,7 @@ public class ScriptConstraint implements Serializable public ScriptConstraintValue getValue(String value) { ScriptConstraintValue[] values = getValues(); - + for(ScriptConstraintValue val : values) { if(val.getValueName().equalsIgnoreCase(value)) @@ -194,39 +195,39 @@ public class ScriptConstraint implements Serializable } return null; } - + public ScriptConstraintValue[] getValues() { // authority, values Map> details = rmCaveatconfigService.getListDetails(info.getName()); - + if (details == null) { details = new HashMap>(); } - + // values, authorities Map> pivot = PivotUtil.getPivot(details); - + // Here with some data to return Set values = pivot.keySet(); - + ArrayList constraints = new ArrayList(pivot.size()); for(String value : values) { ScriptConstraintValue constraint = new ScriptConstraintValue(); constraint.setValueName(value); constraint.setValueTitle(value); - + Listauthorities = pivot.get(value); List sauth = new ArrayList(); for(String authority : authorities) { ScriptAuthority a = new ScriptAuthority(); a.setAuthorityName(authority); - + String displayName = authorityService.getAuthorityDisplayName(authority); - if(displayName != null) + if(StringUtils.isNotBlank(displayName)) { a.setAuthorityTitle(displayName); } @@ -236,10 +237,10 @@ public class ScriptConstraint implements Serializable } sauth.add(a); } - constraint.setAuthorities(sauth); - constraints.add(constraint); + constraint.setAuthorities(sauth); + constraints.add(constraint); } - + /** * Now go through and add any "empty" values */ @@ -251,14 +252,14 @@ public class ScriptConstraint implements Serializable constraint.setValueName(value); constraint.setValueTitle(value); List sauth = new ArrayList(); - constraint.setAuthorities(sauth); + constraint.setAuthorities(sauth); constraints.add(constraint); } } - - + + ScriptConstraintValue[] retVal = constraints.toArray(new ScriptConstraintValue[constraints.size()]); return retVal; } - + }