public static ChildProgressStatusDTO readChildProgressStatus(JsonParser jp) throws IOException { ProgressStatusDTO psd = new ProgressStatusDTO(); int allocatedSteps = 0; while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); jp.nextToken(); // move to value if ("name".equals(fieldname)) { psd.setName(jp.getText()); } else if ("id".equals(fieldname)) { psd.setId(jp.getText()); } else if ("total-step-count".equals(fieldname)) { psd.setTotalStepCount(jp.getIntValue()); } else if ("current-step-count".equals(fieldname)) { psd.setCurrentStepCount(jp.getIntValue()); } else if ("complete".equals(fieldname)) { psd.setCompleted(jp.getBooleanValue()); } else if ("allocated-steps".equals(fieldname)) { allocatedSteps = jp.getIntValue(); } else if ("children".equals(fieldname)) { while (jp.nextToken() != JsonToken.END_ARRAY) { if (jp.getCurrentToken() == JsonToken.START_OBJECT) { ProgressStatusDTO.ChildProgressStatusDTO child = readChildProgressStatus(jp); psd.getChildren().add(child); } } } } return new ChildProgressStatusDTO(allocatedSteps, psd); }
private void mirror(ProgressStatusDTO dto, ProgressStatus stat) { //TODO: copy-paste problem because of ProgressStatusDTO and ProgressStatusBase we have to create shared interface stat.setTotalStepCount(dto.getTotalStepCount()); stat.setCurrentStepCount(dto.getCurrentStepCount()); if (dto.isCompleted()) { stat.complete(); } for (ProgressStatusDTO.ChildProgressStatusDTO chld : dto.getChildren()) { ProgressStatus dst = map.get(chld.getProgressStatus().getId()); if (dst == null) { dst = stat.createChild(chld.getProgressStatus().getName(), chld.getAllocatedSteps()); map.put(chld.getProgressStatus().getId(), dst); } mirror(chld.getProgressStatus(), dst); } }
public static ProgressStatusDTO readProgressStatus(JsonParser jp) throws IOException { ChildProgressStatusDTO child = readChildProgressStatus(jp); return child.getProgressStatus(); }