public QueryResult<VariableSet> addFieldToVariableSet(String studyStr, String variableSetStr, Variable variable, String sessionId) throws CatalogException { if (StringUtils.isEmpty(variable.getId())) { if (StringUtils.isEmpty(variable.getName())) { throw new CatalogException("Missing variable id"); } variable.setId(variable.getName()); } MyResourceId resource = getVariableSetId(variableSetStr, studyStr, sessionId); String userId = resource.getUser(); authorizationManager.checkCanCreateUpdateDeleteVariableSets(resource.getStudyId(), userId); QueryResult<VariableSet> queryResult = studyDBAdaptor.addFieldToVariableSet(resource.getResourceId(), variable, userId); auditManager.recordDeletion(AuditRecord.Resource.variableSet, resource.getResourceId(), userId, queryResult.first(), null, null); return queryResult; }
@Test public void annotationToDB1() throws Exception { Variable v = new Variable().setId("a").setType(Variable.VariableType.BOOLEAN); Set<Variable> setOfVariables = new HashSet<>(); setOfVariables.add(v); VariableSet variableSet = new VariableSet().setVariables(setOfVariables).setUid(1); Map<String, Object> myMap = new HashMap<>(); myMap.put("b", "nothing"); AnnotationConverter annotableConverter = new AnnotationConverter(); List<Document> document1 = annotableConverter.annotationToDB(variableSet, "annotName", myMap); assertTrue(document1.isEmpty()); myMap.put("a", "hello"); List<Document> document2 = annotableConverter.annotationToDB(variableSet, "annotName", myMap); assertEquals(1, document2.size()); assertEquals(5, document2.get(0).size()); assertEquals("a", document2.get(0).get(AnnotationConverter.ID)); assertEquals("annotName", document2.get(0).get(AnnotationConverter.ANNOTATION_SET_NAME)); assertEquals(1L, document2.get(0).get(AnnotationConverter.VARIABLE_SET)); assertEquals("hello", document2.get(0).get(AnnotationConverter.VALUE)); }
bcSet.add(new Variable().setId("c").setMultiValue(true).setType(Variable.VariableType.BOOLEAN)); Set<Variable> bSet = new HashSet<>(); bSet.add(new Variable().setId("b").setType(Variable.VariableType.OBJECT).setVariableSet(bcSet)); Set<Variable> rootSet = new HashSet<>(); rootSet.add(new Variable().setId("a").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(bSet));
bcSet.add(new Variable().setId("c").setType(Variable.VariableType.BOOLEAN)); Set<Variable> bSet = new HashSet<>(); bSet.add(new Variable().setId("b").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(bcSet)); Set<Variable> rootSet = new HashSet<>(); rootSet.add(new Variable().setId("a").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(bSet));
ab1Set.add(new Variable().setId("ab1c1").setMultiValue(true).setType(Variable.VariableType.BOOLEAN)); ab1Set.add(new Variable().setId("ab1c2").setType(Variable.VariableType.TEXT)); ab2c1Set.add(new Variable().setId("ab2c1d1").setMultiValue(true).setType(Variable.VariableType.INTEGER)); ab2c1Set.add(new Variable().setId("ab2c1d2").setType(Variable.VariableType.TEXT)); Set<Variable> ab2Set = new HashSet<>(); ab2Set.add(new Variable().setId("ab2c1").setType(Variable.VariableType.OBJECT).setVariableSet(ab2c1Set)); ab3c1Set.add(new Variable().setId("ab3c1d1").setMultiValue(true).setType(Variable.VariableType.TEXT)); ab3c1Set.add(new Variable().setId("ab3c1d2").setType(Variable.VariableType.DOUBLE)); Set<Variable> ab3Set = new HashSet<>(); ab3Set.add(new Variable().setId("ab3c1").setType(Variable.VariableType.OBJECT).setMultiValue(true).setVariableSet(ab3c1Set)); aSet.add(new Variable().setId("ab1").setType(Variable.VariableType.OBJECT).setVariableSet(ab1Set)); aSet.add(new Variable().setId("ab2").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(ab2Set)); aSet.add(new Variable().setId("ab3").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(ab3Set)); rootSet.add(new Variable().setId("a").setType(Variable.VariableType.OBJECT).setVariableSet(aSet));
ab1Set.add(new Variable().setId("ab1c1").setMultiValue(true).setType(Variable.VariableType.BOOLEAN)); ab1Set.add(new Variable().setId("ab1c2").setType(Variable.VariableType.TEXT)); ab2c1Set.add(new Variable().setId("ab2c1d1").setMultiValue(true).setType(Variable.VariableType.INTEGER)); ab2c1Set.add(new Variable().setId("ab2c1d2").setType(Variable.VariableType.TEXT)); Set<Variable> ab2Set = new HashSet<>(); ab2Set.add(new Variable().setId("ab2c1").setType(Variable.VariableType.OBJECT).setVariableSet(ab2c1Set)); ab3c1Set.add(new Variable().setId("ab3c1d1").setMultiValue(true).setType(Variable.VariableType.TEXT)); ab3c1Set.add(new Variable().setId("ab3c1d2").setType(Variable.VariableType.DOUBLE)); Set<Variable> ab3Set = new HashSet<>(); ab3Set.add(new Variable().setId("ab3c1").setType(Variable.VariableType.OBJECT).setMultiValue(true).setVariableSet(ab3c1Set)); aSet.add(new Variable().setId("ab1").setType(Variable.VariableType.OBJECT).setVariableSet(ab1Set)); aSet.add(new Variable().setId("ab2").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(ab2Set)); aSet.add(new Variable().setId("ab3").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(ab3Set)); rootSet.add(new Variable().setId("a").setType(Variable.VariableType.OBJECT).setVariableSet(aSet));