diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index e5d0310..c750ab0 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -386,6 +386,21 @@ public class Federation extends PathPropertyList return this.organizations; } + /** + * Gets the organizations active. + * + * @return the organizations active + */ + public Organizations getActiveOrganizations() + { + Organizations result; + + result = this.organizations.filterActiveFor(getTechnicalName()); + + // + return result; + } + /** * Gets the service count. * diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index 2eac8de..73f89e9 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -42,6 +42,17 @@ import fr.devinsy.statoolinfos.util.URLUtils; public class Organization extends PathPropertyList { private static final long serialVersionUID = -2709210934548224213L; + + /** + * The Enum Status. + */ + public enum Status + { + ACTIVE, + IDLE, + AWAY + } + private Federation federation; private Services services; private File inputFile; @@ -439,6 +450,44 @@ public class Organization extends PathPropertyList return result; } + /** + * Gets the status member of. + * + * @param entityName + * the entity name + * @return the status member of + */ + public Status getMemberStatusOf(final String entityName) + { + Status result; + + String value = get("organization.memberof." + entityName + ".status"); + + if (StringUtils.isBlank(value)) + { + result = null; + } + else if (StringUtils.equalsIgnoreCase(value, "ACTIVE")) + { + result = Status.ACTIVE; + } + else if (StringUtils.equalsIgnoreCase(value, "IDLE")) + { + result = Status.IDLE; + } + else if (StringUtils.equalsIgnoreCase(value, "AWAY")) + { + result = Status.AWAY; + } + else + { + result = null; + } + + // + return result; + } + /** * Gets the metric month values all. * @@ -666,6 +715,42 @@ public class Organization extends PathPropertyList return result; } + /** + * Gets the status. + * + * @return the status + */ + public Status getStatus() + { + Status result; + + String value = get("organization.status.level", "organization.status"); + + if (StringUtils.isBlank(value)) + { + result = null; + } + else if (StringUtils.equalsIgnoreCase(value, "ACTIVE")) + { + result = Status.ACTIVE; + } + else if (StringUtils.equalsIgnoreCase(value, "IDLE")) + { + result = Status.IDLE; + } + else if (StringUtils.equalsIgnoreCase(value, "AWAY")) + { + result = Status.AWAY; + } + else + { + result = null; + } + + // + return result; + } + /** * Gets the technical guide website. * @@ -860,6 +945,83 @@ public class Organization extends PathPropertyList return result; } + /** + * Checks if is active. + * + * @return true, if is active + */ + public boolean isActive() + { + boolean result; + + if (getStatus() == Status.ACTIVE) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /** + * Checks if is away. + * + * @return true, if is away + */ + public boolean isAway() + { + boolean result; + + Status status = getStatus(); + + if (status == Status.AWAY) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /** + * Checks if is away for. + * + * @param entityName + * the entity name + * @return true, if is away for + */ + public boolean isAwayFor(final String entityName) + { + boolean result; + + Status memberStatus = getMemberStatusOf(entityName); + LocalDate endDate = getDate("organization.memberof." + entityName + ".enddate"); + + if (memberStatus == Status.AWAY) + { + result = true; + } + else if ((endDate == null) || (endDate.isAfter(LocalDate.now()))) + { + result = false; + } + else + { + result = true; + } + + // + return result; + } + /** * Checks if is default. * diff --git a/src/fr/devinsy/statoolinfos/core/Organizations.java b/src/fr/devinsy/statoolinfos/core/Organizations.java index d65d89e..db20ddb 100644 --- a/src/fr/devinsy/statoolinfos/core/Organizations.java +++ b/src/fr/devinsy/statoolinfos/core/Organizations.java @@ -36,6 +36,31 @@ public class Organizations extends ArrayList super(); } + /** + * Filter member of. + * + * @param entityName + * the entity name + * @return the organizations + */ + public Organizations filterActiveFor(final String entityName) + { + Organizations result; + + result = new Organizations(); + + for (Organization organization : this) + { + if ((!organization.isAway()) && (!organization.isAwayFor(entityName))) + { + result.add(organization); + } + } + + // + return result; + } + /** * Filter by social network. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationOrganizationsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationOrganizationsPage.java index b188bb5..ec46bda 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationOrganizationsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationOrganizationsPage.java @@ -78,7 +78,7 @@ public class FederationOrganizationsPage TagDataManager data = new TagDataManager(); data.setContent("federationHeaderView", FederationHeaderView.htmlize(federation)); - data.setContent("organizationListView", OrganizationListView.htmlize(federation.getOrganizations())); + data.setContent("organizationListView", OrganizationListView.htmlize(federation.getActiveOrganizations())); String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationOrganizations.xhtml", data).toString(); diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java index c7730a6..11788d5 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java @@ -21,8 +21,11 @@ package fr.devinsy.statoolinfos.properties; import java.io.File; import java.net.MalformedURLException; import java.net.URL; +import java.time.LocalDate; import java.time.Year; import java.time.YearMonth; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Iterator; import java.util.regex.Matcher; @@ -310,6 +313,38 @@ public class PathPropertyList extends ArrayList implements PathPro return result; } + /** + * Gets the date. + * + * @param path + * the path + * @return the date + */ + public LocalDate getDate(final String path) + { + LocalDate result; + + String value = get(path); + if (value == null) + { + result = null; + } + else + { + try + { + result = LocalDate.parse(value, DateTimeFormatter.ofPattern("dd/MM/yyyy")); + } + catch (DateTimeParseException exception) + { + result = null; + } + } + + // + return result; + } + /** * Gets the index property. *