Skip to content

Commit

Permalink
Internal refactoring of duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Oct 24, 2019
1 parent 32e62f7 commit 8b69e27
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi
}

public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithStringValues(String name, String friendlyName, List<String> values) {
return createAttributeWithStringValues(name, friendlyName, values.toArray(new String[]{}));
if(values.size() > 0) {
return createAttributeWithStringValues(name, friendlyName, values.toArray(new String[]{}));
}
return null;
}

/* Calling this method with name = MDDCConstants.RELEASE_ATTRIBUTES seems to be a special case. In this case,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public ModelRepresentationConversions(CustomPropertiesConfiguration customProper
OpenSamlObjects openSamlObjects = new OpenSamlObjects();
try {
openSamlObjects.init();
}
catch (ComponentInitializationException e) {
} catch (ComponentInitializationException e) {
throw new IllegalStateException(e);
}
ATTRIBUTE_UTILITY = new AttributeUtility(openSamlObjects);
Expand Down Expand Up @@ -81,7 +80,7 @@ public static List<String> getStringListValueOfAttribute(Attribute attribute) {

public static Optional getOverrideByAttributeName(String attributeName) {
return customPropertiesConfiguration.getOverrides().stream().filter(it -> it.getAttributeName().equals(attributeName)).findFirst();
}
}

public static Map<String, Object> getRelyingPartyOverridesRepresentationFromAttributeList(List<Attribute> attributeList) {
Map<String, Object> relyingPartyOverrides = new HashMap<>();
Expand All @@ -91,8 +90,8 @@ public static Map<String, Object> getRelyingPartyOverridesRepresentationFromAttr

Optional override = getOverrideByAttributeName(jpaAttribute.getName());
if (override.isPresent()) {
relyingPartyOverrides.put(((RelyingPartyOverrideProperty)override.get()).getName(),
getOverrideFromAttribute(jpaAttribute));
relyingPartyOverrides.put(((RelyingPartyOverrideProperty) override.get()).getName(),
getOverrideFromAttribute(jpaAttribute));
}
}

Expand All @@ -112,7 +111,7 @@ public static Object getOverrideFromAttribute(Attribute attribute) {
.filter(it -> it.getAttributeFriendlyName().equals(attribute.getFriendlyName())).findFirst().get();

List<XMLObject> attributeValues = attribute.getAttributeValues();
switch(AttributeTypes.valueOf(relyingPartyOverrideProperty.getDisplayType().toUpperCase())) {
switch (AttributeTypes.valueOf(relyingPartyOverrideProperty.getDisplayType().toUpperCase())) {
case BOOLEAN:
if (relyingPartyOverrideProperty.getPersistType() != null
&& (!relyingPartyOverrideProperty.getPersistType().equalsIgnoreCase("boolean"))) {
Expand Down Expand Up @@ -140,11 +139,11 @@ public static String getValueFromXMLObject(XMLObject xmlObject) {
String objectType = xmlObject.getClass().getSimpleName();
switch (objectType) {
case "XSAny":
return ((XSAny)xmlObject).getTextContent();
return ((XSAny) xmlObject).getTextContent();
case "XSString":
return ((XSString)xmlObject).getValue();
return ((XSString) xmlObject).getValue();
case "XSBoolean":
return ((XSBoolean)xmlObject).getStoredValue();
return ((XSBoolean) xmlObject).getStoredValue();
default:
throw new RuntimeException(String.format("Unsupported XML Object type [%s]", objectType));
}
Expand All @@ -157,7 +156,7 @@ public static List<org.opensaml.saml.saml2.core.Attribute> getAttributeListFromA
attributeList.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(MDDCConstants.RELEASE_ATTRIBUTES, attributeReleaseList));
}

return (List<org.opensaml.saml.saml2.core.Attribute>)(List<? extends org.opensaml.saml.saml2.core.Attribute>)attributeList;
return (List<org.opensaml.saml.saml2.core.Attribute>) (List<? extends org.opensaml.saml.saml2.core.Attribute>) attributeList;
}

public static List<org.opensaml.saml.saml2.core.Attribute> getAttributeListFromRelyingPartyOverridesRepresentation
Expand All @@ -182,8 +181,8 @@ public static List<org.opensaml.saml.saml2.core.Attribute> getAttributeListFromA
public static Attribute getAttributeFromObjectAndRelyingPartyOverrideProperty(Object o, RelyingPartyOverrideProperty overrideProperty) {
switch (ModelRepresentationConversions.AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) {
case BOOLEAN:
if ((o instanceof Boolean && ((Boolean)o)) ||
(o instanceof String) && Boolean.valueOf((String)o)) {
if ((o instanceof Boolean && ((Boolean) o)) ||
(o instanceof String) && Boolean.valueOf((String) o)) {
if (overrideProperty.getPersistType() != null &&
!overrideProperty.getPersistType().equalsIgnoreCase("boolean")) {
return ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
Expand All @@ -195,7 +194,7 @@ public static Attribute getAttributeFromObjectAndRelyingPartyOverrideProperty(Ob
overrideProperty.getAttributeFriendlyName(),
Boolean.valueOf((String) o));
} else {
Boolean value = Boolean.valueOf(overrideProperty.getInvert()) ^ (Boolean)o;
Boolean value = Boolean.valueOf(overrideProperty.getInvert()) ^ (Boolean) o;
return ATTRIBUTE_UTILITY.createAttributeWithBooleanValue(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
value);
Expand All @@ -212,25 +211,20 @@ public static Attribute getAttributeFromObjectAndRelyingPartyOverrideProperty(Ob
overrideProperty.getAttributeFriendlyName(),
(String) o);
case SET:
if(((List<String>)o).size() > 0) {
return ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(List<String>) o);
}
return null;
return ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(List<String>) o);

case LIST:
if(((List<String>)o).size() > 0) {
return ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(List<String>) o);
}
return null;
return ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(List<String>) o);

default:
throw new UnsupportedOperationException("getAttributeListFromRelyingPartyOverridesRepresentation was called with an unsupported type (" + overrideProperty.getDisplayType() + ")!");
}
}


public enum AttributeTypes {
BOOLEAN,
INTEGER,
Expand Down

0 comments on commit 8b69e27

Please sign in to comment.