/** * Tries to add a new variable to a non existent variableSet. * @throws CatalogDBException */ @Test public void addFieldToVariableSetTest2() throws CatalogDBException, CatalogAuthorizationException { Variable variable = new Variable("NAM", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap()); thrown.expect(CatalogDBException.class); thrown.expectMessage("not found"); catalogStudyDBAdaptor.addFieldToVariableSet(18, variable, user3.getId()); }
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; }
/** * Creates a new variable once and attempts to create the same one again. * @throws CatalogDBException */ @Test public void addFieldToVariableSetTest1() throws CatalogDBException, CatalogAuthorizationException { createExampleVariableSet("VARSET_1", false); createExampleVariableSet("VARSET_2", true); Variable variable = new Variable("NAM", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap()); QueryResult<VariableSet> queryResult = catalogStudyDBAdaptor.addFieldToVariableSet(18, variable, user3.getId()); // Check that the new variable has been inserted in the variableSet assertTrue(queryResult.first().getVariables().stream().filter(variable1 -> variable.getId().equals(variable1.getId())).findAny() .isPresent()); // We try to insert the same one again. thrown.expect(CatalogDBException.class); thrown.expectMessage("already exist"); catalogStudyDBAdaptor.addFieldToVariableSet(18, variable, user3.getId()); }