@Override public QueryResult<AnnotationSet> getAnnotationSet(long id, @Nullable String annotationSetName) throws CatalogDBException { QueryOptions queryOptions = new QueryOptions(); List<String> includeList = new ArrayList<>(); if (StringUtils.isNotEmpty(annotationSetName)) { includeList.add(Constants.ANNOTATION_SET_NAME + "." + annotationSetName); } else { includeList.add(QueryParams.ANNOTATION_SETS.key()); } queryOptions.put(QueryOptions.INCLUDE, includeList); QueryResult<File> fileQueryResult = get(id, queryOptions); if (fileQueryResult.first().getAnnotationSets().isEmpty()) { return new QueryResult<>("Get annotation set", fileQueryResult.getDbTime(), 0, 0, fileQueryResult.getWarningMsg(), fileQueryResult.getErrorMsg(), Collections.emptyList()); } else { List<AnnotationSet> annotationSets = fileQueryResult.first().getAnnotationSets(); int size = annotationSets.size(); return new QueryResult<>("Get annotation set", fileQueryResult.getDbTime(), size, size, fileQueryResult.getWarningMsg(), fileQueryResult.getErrorMsg(), annotationSets); } }
fileSolrModel.setNumRelatedFiles(file.getRelatedFiles() != null ? file.getRelatedFiles().size() : 0); fileSolrModel.setAnnotations(SolrConverterUtil.populateAnnotations(variableMap, file.getAnnotationSets())); if (file.getAnnotationSets() != null) { fileSolrModel.setAnnotationSets(file.getAnnotationSets().stream().map(AnnotationSet::getId).collect(Collectors.toList())); } else { fileSolrModel.setAnnotationSets(Collections.emptyList());
@Test public void testAnnotations() throws CatalogException, JsonProcessingException { List<Variable> variables = new ArrayList<>(); variables.add(new Variable("var_name", "", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); variables.add(new Variable("AGE", "", "", Variable.VariableType.INTEGER, "", false, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); variables.add(new Variable("HEIGHT", "", "", Variable.VariableType.DOUBLE, "", false, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, sessionIdUser).first(); ObjectMap annotations = new ObjectMap() .append("var_name", "Joe") .append("AGE", 25) .append("HEIGHT", 180); AnnotationSet annotationSet = new AnnotationSet("annotation1", vs1.getId(), annotations); AnnotationSet annotationSet1 = new AnnotationSet("annotation2", vs1.getId(), annotations); ObjectMapper jsonObjectMapper = getDefaultObjectMapper(); ObjectMap updateAnnotation = new ObjectMap() // Update the annotation values .append(FileDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Arrays.asList( new ObjectMap(jsonObjectMapper.writeValueAsString(annotationSet)), new ObjectMap(jsonObjectMapper.writeValueAsString(annotationSet1)) )); QueryResult<File> update = catalogManager.getFileManager().update(studyFqn, "data/", updateAnnotation, QueryOptions.empty(), sessionIdUser); assertEquals(2, update.first().getAnnotationSets().size()); }
List<VariableSet> variableSetList = validateNewAnnotationSetsAndExtractVariableSets(study.getUid(), file.getAnnotationSets());