private void removeAnnotation(Map<String, Object> annotations, String annotation, Set<Variable> variables) throws CatalogException { String[] split = StringUtils.split(annotation, ".", 2); if (split.length > 1) { if (annotations.containsKey(split[0])) { Set<Variable> nestedVariables = null; for (Variable tmpVariable : variables) { if (tmpVariable.getId().equals(split[0])) { nestedVariables = tmpVariable.getVariableSet(); break; } } if (nestedVariables == null) { throw new CatalogException("Internal error. Could not validate removal of variable."); } removeAnnotation((Map<String, Object>) annotations.get(split[0]), split[1], nestedVariables); } } else { for (Variable variable : variables) { if (variable.getId().equals(annotation)) { // We check if the annotation to be remove is mandatory if (variable.isRequired()) { throw new CatalogException("Cannot remove required variable."); } break; } } annotations.remove(annotation); } }
annotation = ((Map<String, Object>) annotation).get(keys.get(i)); if (annotation == null) { if (variable.getDefaultValue() != null && variable.isRequired()) { annotation = ((Map<String, Object>) annotation).get(keys.get(i)); if (annotation == null) { if (variable.getDefaultValue() != null && variable.isRequired()) {
if (addDefaultValues) { if (!addDefaultAnnotation(variable, defaultAnnotations)) { if (variable.isRequired()) { throw new CatalogException("Missing required variable " + variable.getId()); } else { if (variable.isRequired()) { throw new CatalogException("Missing required variable " + variable.getId());
Object realValue = getValue(variable.getType(), value); if (realValue == null) { if (variable.isRequired()) { throw new CatalogException(message + " value '" + value + "' is a required value for " + variable); } else {
@Override public QueryResult<VariableSet> addFieldToVariableSet(long variableSetId, Variable variable, String user) throws CatalogDBException, CatalogAuthorizationException { long startTime = startQuery(); QueryResult<VariableSet> variableSet = getVariableSet(variableSetId, new QueryOptions(), user); checkVariableNotInVariableSet(variableSet.first(), variable.getId()); Bson bsonQuery = Filters.eq(QueryParams.VARIABLE_SET_UID.key(), variableSetId); Bson update = Updates.push(QueryParams.VARIABLE_SET.key() + ".$." + VariableSetParams.VARIABLE.key(), getMongoDBDocument(variable, "variable")); QueryResult<UpdateResult> queryResult = studyCollection.update(bsonQuery, update, null); if (queryResult.first().getModifiedCount() == 0) { throw CatalogDBException.updateError("VariableSet", variableSetId); } if (variable.isRequired()) { dbAdaptorFactory.getCatalogSampleDBAdaptor().addVariableToAnnotations(variableSetId, variable); dbAdaptorFactory.getCatalogCohortDBAdaptor().addVariableToAnnotations(variableSetId, variable); dbAdaptorFactory.getCatalogIndividualDBAdaptor().addVariableToAnnotations(variableSetId, variable); dbAdaptorFactory.getCatalogFamilyDBAdaptor().addVariableToAnnotations(variableSetId, variable); dbAdaptorFactory.getCatalogFileDBAdaptor().addVariableToAnnotations(variableSetId, variable); } return endQuery("Add field to variable set", startTime, getVariableSet(variableSetId, null)); }