throw new Exception(e.getMessage());
}
for (Map<String, Object> workDefinitionMap : workDefinitionsMaps) {
if (workDefinitionMap != null) {
WorkDefinitionImpl workDefinition = new WorkDefinitionImpl();
workDefinition.setName(((String) workDefinitionMap.get("name")).replaceAll("\\s",""));
workDefinition.setDisplayName((String) workDefinitionMap.get("displayName"));
String category = (String) workDefinitionMap.get("category");
if(category == null || category.length() < 1) {
category = DEFAULT_CATEGORY_NAME;
}
workDefinition.setCategory(category);
String icon = (String) workDefinitionMap.get("icon");
Asset<byte[]> iconAsset = null;
if(!icon.startsWith(this.globalDir)) {
if(icon.startsWith("/")) {
icon = this.globalDir + icon;
} else {
icon = this.globalDir + "/" + icon;
}
}
try {
if (!repository.assetExists(icon)) {
icon = this.globalDir + "/defaultservicenodeicon.png";
}
} catch (Exception e) {
_logger.error(e.getMessage());
icon = this.globalDir + "/defaultservicenodeicon.png";
}
iconAsset = repository.loadAssetFromPath(icon);
workDefinition.setIcon(icon);
String iconEncoded = "data:image/png;base64," + javax.xml.bind.DatatypeConverter.printBase64Binary(iconAsset.getAssetContent());
workDefinition.setIconEncoded(URLEncoder.encode(iconEncoded, "UTF-8"));
workDefinition.setCustomEditor((String) workDefinitionMap.get("customEditor"));
Set<ParameterDefinition> parameters = new HashSet<ParameterDefinition>();
if(workDefinitionMap.get("parameters") != null) {
Map<String, DataType> parameterMap = (Map<String, DataType>) workDefinitionMap.get("parameters");
if (parameterMap != null) {
for (Map.Entry<String, DataType> entry : parameterMap.entrySet()) {
parameters.add(new ParameterDefinitionImpl(entry.getKey(), entry.getValue()));
}
}
workDefinition.setParameters(parameters);
}
if(workDefinitionMap.get("results") != null) {
Set<ParameterDefinition> results = new HashSet<ParameterDefinition>();
Map<String, DataType> resultMap = (Map<String, DataType>) workDefinitionMap.get("results");
if (resultMap != null) {
for (Map.Entry<String, DataType> entry : resultMap.entrySet()) {
results.add(new ParameterDefinitionImpl(entry.getKey(), entry.getValue()));
}
}
workDefinition.setResults(results);
}
if(workDefinitionMap.get("defaultHandler") != null) {
workDefinition.setDefaultHandler((String) workDefinitionMap.get("defaultHandler"));
}
if(workDefinitionMap.get("dependencies") != null) {
workDefinition.setDependencies(((List<String>) workDefinitionMap.get("dependencies")).toArray(new String[0]));
}
workDefinitions.put(workDefinition.getName(), workDefinition);
}
}
}