se.vgregion.mobile.hriv.utils.KivwsUnitMapper Maven / Gradle / Ivy
The newest version!
/**
* Copyright 2010 Västra Götalandsregionen
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*/
package se.vgregion.mobile.hriv.utils;
import se.vgregion.mobile.hriv.domain.KivwsAttributes;
import se.vgregion.mobile.hriv.domain.OfficeHours;
import se.vgregion.mobile.hriv.domain.Unit;
import se.vgregion.mobile.hriv.domain.WeekdayTime;
import se.vgregion.mobile.hriv.kivws.Function;
import se.vgregion.mobile.hriv.kivws.String2ArrayOfAnyTypeMap.Entry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Mapp kivws response object to Unit.
*
* @author david bennehult
*
*/
public class KivwsUnitMapper {
private Map> ldapAttributes = new HashMap>();
public Unit mapFromContext(se.vgregion.mobile.hriv.kivws.Unit kivwsUnit) {
Unit unit = new Unit();
ldapAttributes = new HashMap>();
List attributes = kivwsUnit.getAttributes().getValue().getEntry();
for (Entry entry : attributes) {
ldapAttributes.put(entry.getKey(), entry.getValue().getAnyType());
}
populateGeoCoordinates(unit);
// HsaIdentity.
unit.setHsaIdentity(getSingleValue(KivwsAttributes.HSA_IDENTITY));
// Unit name.
populateUnitName(unit);
// Unit locale (l attribute).
unit.setLocale(getSingleValue(KivwsAttributes.L));
// HsaSurgeryHours.
List visitingHours = getMultiValue(KivwsAttributes.HSA_SURGERY_HOURS);
unit.setHsaSurgeryHours(createTimeInterval(visitingHours));
// HsaDropInHours.
List hsaDropInHours = getMultiValue(KivwsAttributes.HSA_DROPIN_HOURS);
unit.setHsaDropInHours(createTimeInterval(hsaDropInHours));
// HsaManagementCodeText (Drivs av).
unit.setHsaManagementCodeText(getSingleValue(KivwsAttributes.HSA_MANAGEMENT_CODE_TEXT));
// HsaPublicTelephoneNumber.
unit.setHsaPublicTelephoneNumber(getSingleValue(KivwsAttributes.HSA_PUBLIC_TELEPHONE_NUMBER));
// HsaTelephoneTime.
List telephoneTime = getMultiValue(KivwsAttributes.HSA_TELEPHONE_TIME);
unit.setHsaTelephoneTime(createTimeInterval(telephoneTime));
// HsaVisitingRuleAge
unit.setHsaVisitingRuleAge(getSingleValue(KivwsAttributes.HSA_VISITING_RULE_AGE));
// HsaLabeledUri.
unit.setLabeleduri(getSingleValue(KivwsAttributes.LABELED_URI));
// Description
unit.setDescription(getSingleValue(KivwsAttributes.DESCRIPTION));
return unit;
}
private void populateUnitName(Unit unit) {
// Name
String ou = getSingleValue(KivwsAttributes.OU);
String unitName;
if (ou!=null && ou.length()>0) {
unitName = ou.replace("\\,", ",");
unit.setName(unitName.trim());
} else {
String cn = getSingleValue(KivwsAttributes.CN);
// change \, to ,
unitName = cn.replace("\\,", ",");
unit.setName(unitName.trim());
}
}
private String getSingleValue(String key) {
String returnValue = "";
if (ldapAttributes.containsKey(key)) {
returnValue = (String) ldapAttributes.get(key).get(0);
}
return returnValue;
}
private List getMultiValue(String key) {
List result = new ArrayList();
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy