@SuppressWarnings("unchecked") @Test public void testUpConvertShouldCollapseAssessmentItem() { Entity saEntity = createUpConvertEntity(); saEntity.getBody().put("assessmentId", "assessmentId"); saEntity.getBody().put("studentId", "studentId"); List<Entity> old = Arrays.asList(saEntity); assertNull("studentAssessmentItem should not be in body", old.get(0).getBody() .get("studentAssessmentItem")); Entity assessment = createAssessment(); when(repo.getTemplate()).thenReturn(template); when(template.findById("assessmentId", Entity.class, EntityNames.ASSESSMENT)).thenReturn(assessment); Iterable<Entity> entities = saConverter.subdocToBodyField(old); assertNotNull("studentAssessmentItem should be moved into body", entities.iterator().next().getBody().get("studentAssessmentItems")); assertNotNull( "assessmentItem should be collapsed into the studentAssessmentItem", ((List<Map<String, Object>>) (entities.iterator().next().getBody().get("studentAssessmentItems"))).get(0).get( "assessmentItem")); Map<String, Object> assessmentItemBody = (Map<String, Object>) ((List<Map<String, Object>>) (entities.iterator().next() .getBody().get("studentAssessmentItems"))).get(0).get("assessmentItem"); assertEquals("collapsed assessmentItem should have assessmentId field is assessmentId", "assessmentId", assessmentItemBody.get("assessmentId")); assertEquals("collapsed assessmentItem should have identificationCode field is code1", "code1", assessmentItemBody.get("identificationCode")); assertEquals("collapsed assessmentItem should have itemCategory is Matching", "Matching", assessmentItemBody.get("itemCategory")); }
@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);  }