@Test public void convertUnitToSeda21Test() throws InvalidParseOperationException, FileNotFoundException { JsonNode jsonUnit = JsonHandler.getFromFile(PropertiesUtils.getResourceFile(UNIT_SEDA_2_0_FILE_1)); Unit unit = new Unit(jsonUnit); assertTrue(unit.get("RestrictionEndDate") != null); Unit convertedUnit = SedaConverterTool.convertUnitToSeda21(unit); System.out.println(BsonHelper.stringify(convertedUnit)); assertConvertedUnitOk(convertedUnit); assertTrue(((Document) ((List)convertedUnit.get("Signature")).get(0)).get("DateSignature") == null); jsonUnit = JsonHandler.getFromFile(PropertiesUtils.getResourceFile(UNIT_SEDA_2_0_FILE_2)); unit = new Unit(jsonUnit); assertTrue(unit.get("Signature") != null); assertTrue(((Document)unit.get("Signature")).get("DateSignature") != null); convertedUnit = SedaConverterTool.convertUnitToSeda21(unit); System.out.println("========================================================================"); System.out.println(BsonHelper.stringify(convertedUnit)); assertConvertedUnitOk(convertedUnit); assertTrue(((Document) ((List)convertedUnit.get("Signature")).get(0)).get("DateSignature") == null); jsonUnit = JsonHandler.getFromFile(PropertiesUtils.getResourceFile(UNIT_SEDA_2_1_FILE_1)); assertConvertedUnitOk(SedaConverterTool.convertUnitToSeda21(new Unit(jsonUnit))); System.out.println("========================================================================"); System.out.println(BsonHelper.stringify(convertedUnit)); }
public static Unit convertUnitToSeda21(Unit unit) { for(ObjectFieldsToDelete objectWrapperFieldsDelete : ObjectFieldsToDelete.values()) { if(ObjectFieldsToDelete.Root.compareTo(objectWrapperFieldsDelete) == 0){ for(String field : objectWrapperFieldsDelete.getFields()){ if(unit.get(field) != null) { unit.remove(field); } } } Object object = unit.get(objectWrapperFieldsDelete.name()); if (object != null && object instanceof Document) { Document document = (Document)object; for(String field : objectWrapperFieldsDelete.getFields()){ if(document.get(field) != null) { document.remove(field); } } } } for(FieldsTreeToTransformToList firstLevelField : FieldsTreeToTransformToList.values()) { Object object = unit.get(firstLevelField.name()); if (object != null && !object.getClass().isArray() && !object.getClass().isAssignableFrom(List.class) && !object.getClass().isAssignableFrom(ArrayList.class)) { if(object instanceof Document && firstLevelField.getFields() != null && firstLevelField.getFields().length > 0){ Document document = (Document)object; for(String subField : firstLevelField.getFields()) { Object subFieldValue = document.get(subField); if(subFieldValue != null){ document.replace(subField, Arrays.asList(subFieldValue)); } } } unit.replace(firstLevelField.name(), Arrays.asList(object)); } } return unit; }
SedaConverterTool { public static Unit convertUnitToSeda21(Unit unit) { for(ObjectFieldsToDelete objectWrapperFieldsDelete : ObjectFieldsToDelete.values()) { if(ObjectFieldsToDelete.Root.compareTo(objectWrapperFieldsDelete) == 0){ for(String field : objectWrapperFieldsDelete.getFields()){ if(unit.get(field) != null) { unit.remove(field); } } } Object object = unit.get(objectWrapperFieldsDelete.name()); if (object != null && object instanceof Document) { Document document = (Document)object; for(String field : objectWrapperFieldsDelete.getFields()){ if(document.get(field) != null) { document.remove(field); } } } } for(FieldsTreeToTransformToList firstLevelField : FieldsTreeToTransformToList.values()) { Object object = unit.get(firstLevelField.name()); if (object != null && !object.getClass().isArray() && !object.getClass().isAssignableFrom(List.class) && !object.getClass().isAssignableFrom(ArrayList.class)) { if(object instanceof Document && firstLevelField.getFields() != null && firstLevelField.getFields().length > 0){ Document document = (Document)object; for(String subField : firstLevelField.getFields()) { Object subFieldValue = document.get(subField); if(subFieldValue != null){ document.replace(subField, Arrays.asList(subFieldValue)); } } } unit.replace(firstLevelField.name(), Arrays.asList(object)); } } return unit; } }
SedaConverterTool { public static Unit convertUnitToSeda21(Unit unit) { for(ObjectFieldsToDelete objectWrapperFieldsDelete : ObjectFieldsToDelete.values()) { if(ObjectFieldsToDelete.Root.compareTo(objectWrapperFieldsDelete) == 0){ for(String field : objectWrapperFieldsDelete.getFields()){ if(unit.get(field) != null) { unit.remove(field); } } } Object object = unit.get(objectWrapperFieldsDelete.name()); if (object != null && object instanceof Document) { Document document = (Document)object; for(String field : objectWrapperFieldsDelete.getFields()){ if(document.get(field) != null) { document.remove(field); } } } } for(FieldsTreeToTransformToList firstLevelField : FieldsTreeToTransformToList.values()) { Object object = unit.get(firstLevelField.name()); if (object != null && !object.getClass().isArray() && !object.getClass().isAssignableFrom(List.class) && !object.getClass().isAssignableFrom(ArrayList.class)) { if(object instanceof Document && firstLevelField.getFields() != null && firstLevelField.getFields().length > 0){ Document document = (Document)object; for(String subField : firstLevelField.getFields()) { Object subFieldValue = document.get(subField); if(subFieldValue != null){ document.replace(subField, Arrays.asList(subFieldValue)); } } } unit.replace(firstLevelField.name(), Arrays.asList(object)); } } return unit; }  }
SedaConverterTool { public static Unit convertUnitToSeda21(Unit unit) { for(ObjectFieldsToDelete objectWrapperFieldsDelete : ObjectFieldsToDelete.values()) { if(ObjectFieldsToDelete.Root.compareTo(objectWrapperFieldsDelete) == 0){ for(String field : objectWrapperFieldsDelete.getFields()){ if(unit.get(field) != null) { unit.remove(field); } } } Object object = unit.get(objectWrapperFieldsDelete.name()); if (object != null && object instanceof Document) { Document document = (Document)object; for(String field : objectWrapperFieldsDelete.getFields()){ if(document.get(field) != null) { document.remove(field); } } } } for(FieldsTreeToTransformToList firstLevelField : FieldsTreeToTransformToList.values()) { Object object = unit.get(firstLevelField.name()); if (object != null && !object.getClass().isArray() && !object.getClass().isAssignableFrom(List.class) && !object.getClass().isAssignableFrom(ArrayList.class)) { if(object instanceof Document && firstLevelField.getFields() != null && firstLevelField.getFields().length > 0){ Document document = (Document)object; for(String subField : firstLevelField.getFields()) { Object subFieldValue = document.get(subField); if(subFieldValue != null){ document.replace(subField, Arrays.asList(subFieldValue)); } } } unit.replace(firstLevelField.name(), Arrays.asList(object)); } } return unit; }  static Unit convertUnitToSeda21(Unit unit); }
SedaConverterTool { public static Unit convertUnitToSeda21(Unit unit) { for(ObjectFieldsToDelete objectWrapperFieldsDelete : ObjectFieldsToDelete.values()) { if(ObjectFieldsToDelete.Root.compareTo(objectWrapperFieldsDelete) == 0){ for(String field : objectWrapperFieldsDelete.getFields()){ if(unit.get(field) != null) { unit.remove(field); } } } Object object = unit.get(objectWrapperFieldsDelete.name()); if (object != null && object instanceof Document) { Document document = (Document)object; for(String field : objectWrapperFieldsDelete.getFields()){ if(document.get(field) != null) { document.remove(field); } } } } for(FieldsTreeToTransformToList firstLevelField : FieldsTreeToTransformToList.values()) { Object object = unit.get(firstLevelField.name()); if (object != null && !object.getClass().isArray() && !object.getClass().isAssignableFrom(List.class) && !object.getClass().isAssignableFrom(ArrayList.class)) { if(object instanceof Document && firstLevelField.getFields() != null && firstLevelField.getFields().length > 0){ Document document = (Document)object; for(String subField : firstLevelField.getFields()) { Object subFieldValue = document.get(subField); if(subFieldValue != null){ document.replace(subField, Arrays.asList(subFieldValue)); } } } unit.replace(firstLevelField.name(), Arrays.asList(object)); } } return unit; }  static Unit convertUnitToSeda21(Unit unit);  }