package com.onaro.sanscreen.client.view.actions.application; import org.apache.commons.lang3.StringUtils; import com.onaro.sanscreen.server.interfaces.data.inventory.BusinessEntity; /** * Level of the BE. Coincides with depth in tree. */ public enum BusinessEntityLevel { ROOT, TENANT, LOB, BU, PROJECT; public static String getValueAtLevel(BusinessEntity be, BusinessEntityLevel level) { String value = null; if(be != null) { switch (level) { case TENANT: value = be.getTenant(); break; case LOB: value = be.getLineOfBusiness(); break; case BU: value = be.getBusinessUnit(); break; case PROJECT: value = be.getProject(); break; } } return (value); } public static String getValueAtLevel(com.onaro.sanscreen.server.dataobject.historyobject.application.BusinessEntity be, BusinessEntityLevel level) { String value = null; if(be != null) { switch (level) { case TENANT: value = be.getTenant(); break; case LOB: value = be.getLineOfBusiness(); break; case BU: value = be.getBusinessUnit(); break; case PROJECT: value = be.getProject(); break; } } return (value); } public static String getPrefixForLevel(BusinessEntityLevel level) { String prefix = null; switch (level) { case TENANT: prefix = Messages.INSTANCE.getTenantPrefix(); break; case LOB: prefix = Messages.INSTANCE.getLineOfBusinessPrefix(); break; case BU: prefix = Messages.INSTANCE.getBusinessUnitPrefix(); break; case PROJECT: prefix = Messages.INSTANCE.getProjectPrefix(); break; } return (prefix); } /** * Copies the value at the given level of a BE from the srcBE to the destBE. * * @param destBE destination BE * @param srcBE source BE * @param level which level of the BE to copy. */ public static void setValueAtLevel(BusinessEntity destBE, BusinessEntity srcBE, BusinessEntityLevel level) { setValueAtLevel(destBE, level, getValueAtLevel(srcBE, level)); } /** * Copies the value at the given level of a BE to the given value. * * @param be destination BE * @param level which level of the BE to copy. * @param value the value to copy */ public static void setValueAtLevel(BusinessEntity be, BusinessEntityLevel level, String value) { switch (level) { case TENANT: be.setTenant(value); break; case LOB: be.setLineOfBusiness(value); break; case BU: be.setBusinessUnit(value); break; case PROJECT: be.setProject(value); break; } } /** * * @param level * the level to test * @return the previous level or the top most level if the level is already the top most. */ public static BusinessEntityLevel getPreviousLevel(BusinessEntityLevel level) { if (level == TENANT) { return (TENANT); } return (values()[level.ordinal() - 1]); } /** * * @param level * the level to test * @return the next level or the last level if the level is already the last level. */ public static BusinessEntityLevel getNextLevel(BusinessEntityLevel level) { if (level == PROJECT) { return (PROJECT); } return (values()[level.ordinal() + 1]); } /** * @param be * the BusinessEntity to test * @param level * the level to test * @return true if this level is empty and all child levels are empty. */ public static boolean isEmptyLevelPath(BusinessEntity be, BusinessEntityLevel level) { while (level != PROJECT) { if (StringUtils.isNotEmpty(getValueAtLevel(be, level))) { return (false); } level = getNextLevel(level); } return (StringUtils.isEmpty(getValueAtLevel(be, level))); } }