/******************************************************************************* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. *******************************************************************************/ package at.gv.egovernment.moa.id.configuration.data.oa; import java.util.Arrays; import java.util.List; import javax.servlet.http.HttpServletRequest; import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentOA; import at.gv.egovernment.moa.id.commons.db.dao.config.IdentificationNumber; import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; import at.gv.egovernment.moa.id.commons.validation.TargetValidator; import at.gv.egovernment.moa.id.configuration.Constants; import at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser; import at.gv.egovernment.moa.id.configuration.validation.oa.OAGeneralConfigValidation; import at.gv.egovernment.moa.util.MiscUtil; public class OAGeneralConfig implements IOnlineApplicationData{ private boolean isActive = false; private String dbID = null; private String identifier = null; private String friendlyName = null; private boolean businessService = false; private boolean deaktivededBusinessService = false; private boolean subTargetSet = false; private String target = null; private String target_subsector = null; private String target_admin = null; private static List targetList = null; private String targetFriendlyName = null; private boolean isAdminTarget = false; private String identificationNumber = null; private String identificationType = null; private static List identificationTypeList = null; public OAGeneralConfig() { targetList = TargetValidator.getListOfTargets(); target = ""; identificationTypeList = Arrays.asList( Constants.IDENIFICATIONTYPE_FN, Constants.IDENIFICATIONTYPE_ZVR, Constants.IDENIFICATIONTYPE_ERSB, Constants.IDENIFICATIONTYPE_STORK); } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#getName() */ @Override public String getName() { return "OAGeneralInformation"; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#parse(at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication, javax.servlet.http.HttpServletRequest) */ @Override public List parse(OnlineApplication dbOAConfig, AuthenticatedUser authUser, HttpServletRequest request) { isActive = dbOAConfig.isIsActive(); friendlyName = dbOAConfig.getFriendlyName(); identifier = dbOAConfig.getPublicURLPrefix(); subTargetSet = MiscUtil.isNotEmpty(getTarget_subsector()); String target_full = dbOAConfig.getTarget(); if (MiscUtil.isNotEmpty(target_full)) { if (TargetValidator.isValidTarget(target_full)) { target = target_full; } else { String[] target_split = target_full.split("-"); if (TargetValidator.isValidTarget(target_split[0])) { target = target_split[0]; if (target_split.length > 1) target_subsector = target_split[1]; } else { target = ""; target_subsector = null; target_admin = target_full; isAdminTarget = true; } } targetFriendlyName = dbOAConfig.getTargetFriendlyName(); } if (dbOAConfig.getType().equals(Constants.MOA_CONFIG_BUSINESSSERVICE)) businessService = true; else businessService = false; AuthComponentOA oaauth = dbOAConfig.getAuthComponentOA(); if (oaauth != null) { IdentificationNumber idnumber = oaauth.getIdentificationNumber(); if (idnumber != null) { String number = idnumber.getValue(); if (MiscUtil.isNotEmpty(number)) { String[] split = number.split("\\+"); if (Constants.PREFIX_WPBK.startsWith(split[0]) && split.length >= 2) { identificationType = split[1]; identificationNumber = split[2]; } else if (Constants.PREFIX_STORK.startsWith(split[0]) && split.length >= 2) { //identificationType = split[1]; // setting at as iden category ? identificationType = Constants.IDENIFICATIONTYPE_STORK; identificationNumber = split[2]; // setting sp country as ident type -> sp ident } } if (authUser.isOnlyBusinessService()) { deaktivededBusinessService = authUser.isOnlyBusinessService(); setBusinessService(authUser.isOnlyBusinessService()); identificationType = authUser.getBusinessServiceType(); identificationNumber = authUser.getBusinessServiceNumber(); } } } return null; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#store(at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication, at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser, javax.servlet.http.HttpServletRequest) */ @Override public String store(OnlineApplication dbOA, AuthenticatedUser authUser, HttpServletRequest request) { AuthComponentOA authoa = dbOA.getAuthComponentOA(); if (authoa == null) { authoa = new AuthComponentOA(); dbOA.setAuthComponentOA(authoa); } if (authUser.isAdmin()) dbOA.setIsActive(isActive()); dbOA.setPublicURLPrefix(getIdentifier()); dbOA.setFriendlyName(getFriendlyName()); if (isBusinessService() || authUser.isOnlyBusinessService()) { dbOA.setType(Constants.MOA_CONFIG_BUSINESSSERVICE); String num = null; if (authUser.isOnlyBusinessService()) { deaktivededBusinessService = authUser.isOnlyBusinessService(); setBusinessService(authUser.isOnlyBusinessService()); num = authUser.getBusinessServiceType() + authUser.getBusinessServiceNumber(); } else { num = getIdentificationNumber().replaceAll(" ", ""); if (num.startsWith(Constants.IDENIFICATIONTYPE_FN)) { num = num.substring(Constants.IDENIFICATIONTYPE_FN.length()); num = at.gv.egovernment.moa.util.StringUtils.deleteLeadingZeros(num); // num = StringUtils.leftPad(num, 7, '0'); } if (num.startsWith(Constants.IDENIFICATIONTYPE_ZVR)) num = num.substring(Constants.IDENIFICATIONTYPE_ZVR.length()); if (num.startsWith(Constants.IDENIFICATIONTYPE_ERSB)) num = num.substring(Constants.IDENIFICATIONTYPE_ERSB.length()); } IdentificationNumber idnumber = new IdentificationNumber(); if (getIdentificationType().equals(Constants.IDENIFICATIONTYPE_STORK)) { idnumber.setValue(Constants.PREFIX_STORK + "AT" + "+" + num); idnumber.setType(Constants.BUSINESSSERVICENAMES.get(getIdentificationType())); } else { idnumber.setValue(Constants.PREFIX_WPBK + getIdentificationType() + "+" + num); idnumber.setType(Constants.BUSINESSSERVICENAMES.get(getIdentificationType())); } authoa.setIdentificationNumber(idnumber); } else { dbOA.setType(null); if (authUser.isAdmin()) { if (MiscUtil.isNotEmpty(getTarget_admin()) && isAdminTarget()) { dbOA.setTarget(getTarget_admin()); dbOA.setTargetFriendlyName(getTargetFriendlyName()); } else { String target = getTarget(); if (MiscUtil.isNotEmpty(getTarget_subsector()) && subTargetSet) dbOA.setTarget(target + "-" + getTarget_subsector()); else dbOA.setTarget(target); String targetname = TargetValidator.getTargetFriendlyName(target); if (MiscUtil.isNotEmpty(targetname)) dbOA.setTargetFriendlyName(targetname); } } else { if (MiscUtil.isNotEmpty(getTarget())) { String target = getTarget(); if (MiscUtil.isNotEmpty(getTarget_subsector()) && subTargetSet) dbOA.setTarget(target + "-" + getTarget_subsector()); else dbOA.setTarget(target); String targetname = TargetValidator.getTargetFriendlyName(target); if (MiscUtil.isNotEmpty(targetname)) dbOA.setTargetFriendlyName(targetname); } } } return null; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#validate(at.gv.egovernment.moa.id.configuration.data.oa.OAGeneralConfig, at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser, javax.servlet.http.HttpServletRequest) */ @Override public List validate(OAGeneralConfig general, AuthenticatedUser authUser, HttpServletRequest request) { return new OAGeneralConfigValidation().validate(this, authUser.isAdmin(), request); } public String getIdentifier() { return identifier; } public void setIdentifier(String identifier) { this.identifier = identifier; } public String getFriendlyName() { return friendlyName; } public void setFriendlyName(String friendlyName) { this.friendlyName = friendlyName; } public String getTarget() { return target; } public void setTarget(String target) { this.target = target; } public String getTargetFriendlyName() { return targetFriendlyName; } public void setTargetFriendlyName(String targetFriendlyName) { this.targetFriendlyName = targetFriendlyName; } public String getIdentificationNumber() { return identificationNumber; } public void setIdentificationNumber(String identificationNumber) { this.identificationNumber = identificationNumber; } public String getIdentificationType() { return identificationType; } public void setIdentificationType(String identificationType) { this.identificationType = identificationType; } public boolean isActive() { return isActive; } public void setActive(boolean isActive) { this.isActive = isActive; } public boolean isBusinessService() { return businessService; } public void setBusinessService(boolean businessService) { this.businessService = businessService; } /** * @return the dbID */ public String getDbID() { return dbID; } /** * @param dbID the dbID to set */ public void setDbID(long dbID) { this.dbID = String.valueOf(dbID); } /** * @param dbID the dbID to set */ public void setDbID(String dbID) { this.dbID = dbID; } /** * @return the target_subsector */ public String getTarget_subsector() { return target_subsector; } /** * @param target_subsector the target_subsector to set */ public void setTarget_subsector(String target_subsector) { this.target_subsector = target_subsector; } /** * @return the target_admin */ public String getTarget_admin() { return target_admin; } /** * @param target_admin the target_admin to set */ public void setTarget_admin(String target_admin) { this.target_admin = target_admin; } /** * @return the targetList */ public List getTargetList() { return targetList; } /** * @return the identificationTypeList */ public List getIdentificationTypeList() { return identificationTypeList; } /** * @return the isAdminTarget */ public boolean isAdminTarget() { return isAdminTarget; } /** * @param isAdminTarget the isAdminTarget to set */ public void setAdminTarget(boolean isAdminTarget) { this.isAdminTarget = isAdminTarget; } /** * @return the deaktivededBusinessService */ public boolean isDeaktivededBusinessService() { return deaktivededBusinessService; } /** * @param deaktivededBusinessService the deaktivededBusinessService to set */ public void setDeaktivededBusinessService(boolean deaktivededBusinessService) { this.deaktivededBusinessService = deaktivededBusinessService; } }