fish.focus.uvms.plugins.ais.mapper.ServiceMapper Maven / Gradle / Ivy
The newest version!
/*
Developed with the contribution of the European Commission - Directorate General for Maritime Affairs and Fisheries
© European Union, 2015-2016.
This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can
redistribute it and/or modify it under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or any later version. The IFDM Suite 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 General Public License for more details. You should have received a
copy of the GNU General Public License along with the IFDM Suite. If not, see .
*/
package fish.focus.uvms.plugins.ais.mapper;
import fish.focus.schema.exchange.plugin.types.v1.PluginType;
import fish.focus.schema.exchange.service.v1.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentMap;
/**
*
**/
public class ServiceMapper {
private static final Logger LOG = LoggerFactory.getLogger(ServiceMapper.class);
private ServiceMapper() {
}
public static ServiceType getServiceType(String serviceClassName, String aisDisplayName, String description, PluginType aisType, String responseMessageName) {
if (responseMessageName == null) {
throw new IllegalArgumentException("Response message must be provided!");
}
if (serviceClassName == null) {
throw new IllegalArgumentException("ServiceClassName message must be provided!");
}
ServiceType serviceType = new ServiceType();
serviceType.setDescription(description);
serviceType.setName(aisDisplayName);
serviceType.setServiceClassName(serviceClassName);
serviceType.setServiceResponseMessageName(responseMessageName);
serviceType.setPluginType(aisType);
return serviceType;
}
public static SettingListType getSettingsListTypeFromMap(ConcurrentMap settings) {
SettingListType settingListType = new SettingListType();
Iterator> itr = settings.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry tmp = itr.next();
SettingType setting = new SettingType();
setting.setKey(tmp.getKey());
setting.setValue(tmp.getValue());
settingListType.getSetting().add(setting);
}
return settingListType;
}
public static CapabilityListType getCapabilitiesListTypeFromMap(ConcurrentMap capabilities) {
CapabilityListType capabilityListType = new CapabilityListType();
Iterator> itr = capabilities.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry tmp = itr.next();
CapabilityType setting = new CapabilityType();
try {
setting.setType(CapabilityTypeType.valueOf(tmp.getKey()));
} catch (Exception e) {
LOG.error("Error when parsing to Enum type from String KEY: {}", tmp.getKey());
}
setting.setValue(tmp.getValue());
capabilityListType.getCapability().add(setting);
}
return capabilityListType;
}
public static void mapToMapFromProperties(ConcurrentMap map, Properties props, String registerClassName) {
for (Object col : props.keySet()) {
if (col.getClass().isAssignableFrom(String.class)) {
String keyString = (String) col;
if (registerClassName != null) {
keyString = registerClassName.concat("." + keyString);
}
String valueString = (String) props.get(col);
map.put(keyString, valueString);
}
}
}
}