Skip to content

Commit

Permalink
[SHIBUI-1226]
Browse files Browse the repository at this point in the history
refactor
fix MDUI updates
  • Loading branch information
jj committed Feb 14, 2019
1 parent 7ef641e commit b407f16
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import javax.annotation.Nullable;
import javax.persistence.Entity;
import javax.persistence.Transient;
import java.util.Collections;
import java.util.List;
import java.util.Optional;


@Entity
Expand All @@ -17,4 +19,14 @@ public class Extensions extends AbstractElementExtensibleXMLObject implements or
public List<XMLObject> getOrderedChildren() {
return Collections.unmodifiableList(this.getUnknownXMLObjects());
}

@Transient
public Optional<UIInfo> getOptionalUIInfo() {
List uiinfos = this.getUnknownXMLObjects(UIInfo.DEFAULT_ELEMENT_NAME);
if (uiinfos.size() == 0) {
return Optional.empty();
} else {
return Optional.of((UIInfo) uiinfos.get(0));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Entity
@EqualsAndHashCode(callSuper = true)
Expand Down Expand Up @@ -116,4 +117,9 @@ public List<XMLObject> getOrderedChildren() {

return Collections.unmodifiableList(children);
}

@Transient
public Optional<Extensions> getOptionalExtensions() {
return Optional.ofNullable(this.getExtensions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Transient;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ private EntityDescriptor buildDescriptorFromRepresentation(final EntityDescripto
displayName.setValue(mduiRepresentation.getDisplayName());
displayName.setXMLLang("en");
} else {
if (getUIInfo(ed).getXMLObjects(DisplayName.DEFAULT_ELEMENT_NAME).size() > 0) {
getUIInfo(ed).getXMLObjects().remove(getUIInfo(ed).getXMLObjects(DisplayName.DEFAULT_ELEMENT_NAME).get(0));
}
getOptionalSPSSODescriptorFromEntityDescriptor(ed)
.flatMap(SPSSODescriptor::getOptionalExtensions)
.flatMap(Extensions::getOptionalUIInfo)
.ifPresent(u -> u.getXMLObjects().removeAll(u.getDisplayNames()));
}

if (!Strings.isNullOrEmpty(mduiRepresentation.getInformationUrl())) {
Expand All @@ -201,9 +202,10 @@ private EntityDescriptor buildDescriptorFromRepresentation(final EntityDescripto
informationURL.setValue(mduiRepresentation.getInformationUrl());
informationURL.setXMLLang("en");
} else {
if (getUIInfo(ed).getXMLObjects(InformationURL.DEFAULT_ELEMENT_NAME).size() > 0) {
getUIInfo(ed).getXMLObjects().remove(getUIInfo(ed).getXMLObjects(InformationURL.DEFAULT_ELEMENT_NAME).get(0));
}
getOptionalSPSSODescriptorFromEntityDescriptor(ed)
.flatMap(SPSSODescriptor::getOptionalExtensions)
.flatMap(Extensions::getOptionalUIInfo)
.ifPresent(u -> u.getXMLObjects().removeAll(u.getInformationURLs()));
}

if (!Strings.isNullOrEmpty(mduiRepresentation.getPrivacyStatementUrl())) {
Expand All @@ -212,9 +214,10 @@ private EntityDescriptor buildDescriptorFromRepresentation(final EntityDescripto
privacyStatementURL.setValue(mduiRepresentation.getPrivacyStatementUrl());
privacyStatementURL.setXMLLang("en");
} else {
if (getUIInfo(ed).getXMLObjects(PrivacyStatementURL.DEFAULT_ELEMENT_NAME).size() > 0) {
getUIInfo(ed).getXMLObjects().remove(getUIInfo(ed).getXMLObjects(PrivacyStatementURL.DEFAULT_ELEMENT_NAME).get(0));
}
getOptionalSPSSODescriptorFromEntityDescriptor(ed)
.flatMap(SPSSODescriptor::getOptionalExtensions)
.flatMap(Extensions::getOptionalUIInfo)
.ifPresent(u -> u.getXMLObjects().removeAll(u.getPrivacyStatementURLs()));
}

if (!Strings.isNullOrEmpty(mduiRepresentation.getDescription())) {
Expand All @@ -223,9 +226,10 @@ private EntityDescriptor buildDescriptorFromRepresentation(final EntityDescripto
description.setValue(mduiRepresentation.getDescription());
description.setXMLLang("en");
} else {
if (getUIInfo(ed).getXMLObjects(Description.DEFAULT_ELEMENT_NAME).size() > 0) {
getUIInfo(ed).getXMLObjects().remove(getUIInfo(ed).getXMLObjects(Description.DEFAULT_ELEMENT_NAME).get(0));
}
getOptionalSPSSODescriptorFromEntityDescriptor(ed)
.flatMap(SPSSODescriptor::getOptionalExtensions)
.flatMap(Extensions::getOptionalUIInfo)
.ifPresent(u -> u.getXMLObjects().removeAll(u.getDescriptions()));
}

if (!Strings.isNullOrEmpty(mduiRepresentation.getLogoUrl())) {
Expand All @@ -236,9 +240,10 @@ private EntityDescriptor buildDescriptorFromRepresentation(final EntityDescripto
logo.setWidth(mduiRepresentation.getLogoWidth());
logo.setXMLLang("en");
} else {
if (getUIInfo(ed).getXMLObjects(Description.DEFAULT_ELEMENT_NAME).size() > 0) {
getUIInfo(ed).getXMLObjects().remove(getUIInfo(ed).getXMLObjects(Description.DEFAULT_ELEMENT_NAME).get(0));
}
getOptionalSPSSODescriptorFromEntityDescriptor(ed)
.flatMap(SPSSODescriptor::getOptionalExtensions)
.flatMap(Extensions::getOptionalUIInfo)
.ifPresent(u -> u.getXMLObjects().removeAll(u.getLogos()));
}
} else {
removeUIInfo(ed);
Expand Down

0 comments on commit b407f16

Please sign in to comment.