@Test public void upconvertNoAssessmentShouldRemoveInvalidReference() { List<Entity> old = Arrays.asList(createUpConvertEntity()); assertNotNull(old.get(0).getEmbeddedData().get("studentAssessmentItem")); Iterable<Entity> entity = saConverter.subdocToBodyField(old); assertNull(entity.iterator().next().getEmbeddedData().get("studentAssessmentItem")); }
@Override public Entity subdocToBodyField(Entity entity) { if (entity != null && entity.getType().equals(STUDENT_ASSESSMENT)) { if (entity.getBody() == null || entity.getBody().isEmpty()) { return null; } Entity assessment = retrieveAssessment(entity.getBody().get(ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_ASSESSMENT_ITEM, ASSESSMENT_ITEM_ID, ASSESSMENT_ITEM); subdocsToBody(entity, STUDENT_ASSESSMENT_ITEM, "studentAssessmentItems", Arrays.asList(STUDENT_ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_OBJECTIVE_ASSESSMENT, OBJECTIVE_ASSESSMENT_ID, OBJECTIVE_ASSESSMENT); subdocsToBody(entity, STUDENT_OBJECTIVE_ASSESSMENT, "studentObjectiveAssessments", Arrays.asList(STUDENT_ASSESSMENT_ID)); entity.getEmbeddedData().clear(); } return entity; }
StudentAssessmentConverter extends GenericSuperdocConverter implements SuperdocConverter { @Override public Entity subdocToBodyField(Entity entity) { if (entity != null && entity.getType().equals(STUDENT_ASSESSMENT)) { if (entity.getBody() == null || entity.getBody().isEmpty()) { return null; } Entity assessment = retrieveAssessment(entity.getBody().get(ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_ASSESSMENT_ITEM, ASSESSMENT_ITEM_ID, ASSESSMENT_ITEM); subdocsToBody(entity, STUDENT_ASSESSMENT_ITEM, "studentAssessmentItems", Arrays.asList(STUDENT_ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_OBJECTIVE_ASSESSMENT, OBJECTIVE_ASSESSMENT_ID, OBJECTIVE_ASSESSMENT); subdocsToBody(entity, STUDENT_OBJECTIVE_ASSESSMENT, "studentObjectiveAssessments", Arrays.asList(STUDENT_ASSESSMENT_ID)); entity.getEmbeddedData().clear(); } return entity; } }
StudentAssessmentConverter extends GenericSuperdocConverter implements SuperdocConverter { @Override public Entity subdocToBodyField(Entity entity) { if (entity != null && entity.getType().equals(STUDENT_ASSESSMENT)) { if (entity.getBody() == null || entity.getBody().isEmpty()) { return null; } Entity assessment = retrieveAssessment(entity.getBody().get(ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_ASSESSMENT_ITEM, ASSESSMENT_ITEM_ID, ASSESSMENT_ITEM); subdocsToBody(entity, STUDENT_ASSESSMENT_ITEM, "studentAssessmentItems", Arrays.asList(STUDENT_ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_OBJECTIVE_ASSESSMENT, OBJECTIVE_ASSESSMENT_ID, OBJECTIVE_ASSESSMENT); subdocsToBody(entity, STUDENT_OBJECTIVE_ASSESSMENT, "studentObjectiveAssessments", Arrays.asList(STUDENT_ASSESSMENT_ID)); entity.getEmbeddedData().clear(); } return entity; }  }
StudentAssessmentConverter extends GenericSuperdocConverter implements SuperdocConverter { @Override public Entity subdocToBodyField(Entity entity) { if (entity != null && entity.getType().equals(STUDENT_ASSESSMENT)) { if (entity.getBody() == null || entity.getBody().isEmpty()) { return null; } Entity assessment = retrieveAssessment(entity.getBody().get(ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_ASSESSMENT_ITEM, ASSESSMENT_ITEM_ID, ASSESSMENT_ITEM); subdocsToBody(entity, STUDENT_ASSESSMENT_ITEM, "studentAssessmentItems", Arrays.asList(STUDENT_ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_OBJECTIVE_ASSESSMENT, OBJECTIVE_ASSESSMENT_ID, OBJECTIVE_ASSESSMENT); subdocsToBody(entity, STUDENT_OBJECTIVE_ASSESSMENT, "studentObjectiveAssessments", Arrays.asList(STUDENT_ASSESSMENT_ID)); entity.getEmbeddedData().clear(); } return entity; }  @Override Entity subdocToBodyField(Entity entity); @Override void bodyFieldToSubdoc(Entity entity); @Override void bodyFieldToSubdoc(Entity entity, SuperdocConverter.Option option); @Override Iterable<Entity> subdocToBodyField(Iterable<Entity> entities); @Override void bodyFieldToSubdoc(Iterable<Entity> entities); @Override void bodyFieldToSubdoc(Iterable<Entity> entities, SuperdocConverter.Option option); }
StudentAssessmentConverter extends GenericSuperdocConverter implements SuperdocConverter { @Override public Entity subdocToBodyField(Entity entity) { if (entity != null && entity.getType().equals(STUDENT_ASSESSMENT)) { if (entity.getBody() == null || entity.getBody().isEmpty()) { return null; } Entity assessment = retrieveAssessment(entity.getBody().get(ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_ASSESSMENT_ITEM, ASSESSMENT_ITEM_ID, ASSESSMENT_ITEM); subdocsToBody(entity, STUDENT_ASSESSMENT_ITEM, "studentAssessmentItems", Arrays.asList(STUDENT_ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_OBJECTIVE_ASSESSMENT, OBJECTIVE_ASSESSMENT_ID, OBJECTIVE_ASSESSMENT); subdocsToBody(entity, STUDENT_OBJECTIVE_ASSESSMENT, "studentObjectiveAssessments", Arrays.asList(STUDENT_ASSESSMENT_ID)); entity.getEmbeddedData().clear(); } return entity; }  @Override Entity subdocToBodyField(Entity entity); @Override void bodyFieldToSubdoc(Entity entity); @Override void bodyFieldToSubdoc(Entity entity, SuperdocConverter.Option option); @Override Iterable<Entity> subdocToBodyField(Iterable<Entity> entities); @Override void bodyFieldToSubdoc(Iterable<Entity> entities); @Override void bodyFieldToSubdoc(Iterable<Entity> entities, SuperdocConverter.Option option);  }