Commit 63ffd776 authored by Brian Long's avatar Brian Long
Browse files

fixed NPE on expressions

parent 4d064916
Loading
Loading
Loading
Loading
+20 −14
Original line number Diff line number Diff line
@@ -241,25 +241,31 @@ public class ApsProcessJsonTranslator extends ApsOrganizationHandler implements
		String idField = prefix == null ? "id" : prefix + "Id";
		
		ObjectNode jsonRef = (ObjectNode)_jsonRef;
		String modelName = jsonRef.get(nameField).asText();
		JsonNode jsonName = jsonRef.get(nameField);
		if (jsonName == null) {
            this.logger.trace("The expression does not have an APS model name field ({})", nameField);
            return false;
		}
		
		String modelName = jsonName.asText();
		this.logger.trace("Found model '{}' in the APS Process descriptor", modelName);
		if (!apsIndex.containsValue(modelName)) {
            this.logger.debug("The model '{}' does not exists in APS; leaving unchanged", modelName);
            return false;
		}
		
		if (apsIndex.containsValue(modelName)) {
			long modelId = jsonRef.get(idField).asLong();
		JsonNode jsonId = jsonRef.get(idField);
		long modelId = jsonId == null ? -1L : jsonId.asLong();
		long apsModelId = apsIndex.getFirstKey(modelName);
		if (apsModelId != modelId) {
				this.logger.debug("The model '{}' exists in APS with ID {}; leaving unchanged", modelName, apsModelId);
			this.logger.debug("The model '{}' exists in APS with ID {}", modelName, apsModelId);
			jsonRef.put(idField, apsModelId);
			return true;
		} else {
			this.logger.trace("The model '{}' ID does not change; leaving unchanged", modelName);
			}
		} else {
			this.logger.debug("The model '{}' does not exists in APS; leaving unchanged", modelName);
		}
		
	        return false;
		}
	}