use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method allowTaxonomyLevelTypeAllowedSubType.
@Test
public void allowTaxonomyLevelTypeAllowedSubType() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-4", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-4", "Type 4 on rest", "Type", "EXT-Type-4", taxonomy);
TaxonomyLevelType subType1 = taxonomyService.createTaxonomyLevelType("REST-Type-4-1", "Type 4.1 on rest", "Type", "EXT-Type-4-1", taxonomy);
TaxonomyLevelType subType2 = taxonomyService.createTaxonomyLevelType("REST-Type-4-2", "Type 4.2 on rest", "Type", "EXT-Type-4-2", taxonomy);
dbInstance.commit();
type = taxonomyService.updateTaxonomyLevelType(type, Collections.singletonList(subType1));
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("types").path(type.getKey().toString()).path("allowedSubTypes").path(subType2.getKey().toString()).build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
TaxonomyLevelType reloadedType = taxonomyService.getTaxonomyLevelType(type);
Set<TaxonomyLevelTypeToType> typeToTypes = reloadedType.getAllowedTaxonomyLevelSubTypes();
Assert.assertEquals(2, typeToTypes.size());
boolean found1 = false;
boolean found2 = false;
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
TaxonomyLevelType subType = typeToType.getAllowedSubTaxonomyLevelType();
if (subType1.getKey().equals(subType.getKey())) {
found1 = true;
} else if (subType2.getKey().equals(subType.getKey())) {
found2 = true;
}
}
Assert.assertTrue(found1);
Assert.assertTrue(found2);
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method putTaxonomyLevel_subLevel.
@Test
public void putTaxonomyLevel_subLevel() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-3", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Tax-r-1", "Root level on rest", "Level", "Ext-23", null, null, taxonomy);
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("Sub-type", "Type for a sub level", "All is in the title", "TYP-23", taxonomy);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
String uid = UUID.randomUUID().toString();
TaxonomyLevelVO levelVo = new TaxonomyLevelVO();
levelVo.setIdentifier(uid);
levelVo.setDisplayName("PUT a sub level");
levelVo.setDescription("Try to PUT a level above the root");
levelVo.setExternalId("EXT-191");
levelVo.setParentKey(rootLevel.getKey());
levelVo.setTypeKey(type.getKey());
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, levelVo);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// check the returned value
TaxonomyLevelVO newTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
Assert.assertNotNull(newTaxonomyLevelVo);
Assert.assertNotNull(newTaxonomyLevelVo.getKey());
Assert.assertEquals(uid, newTaxonomyLevelVo.getIdentifier());
Assert.assertEquals("PUT a sub level", newTaxonomyLevelVo.getDisplayName());
Assert.assertEquals("EXT-191", newTaxonomyLevelVo.getExternalId());
Assert.assertEquals(rootLevel.getKey(), newTaxonomyLevelVo.getParentKey());
Assert.assertEquals(type.getKey(), newTaxonomyLevelVo.getTypeKey());
// check the database
TaxonomyLevel savedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(newTaxonomyLevelVo.getKey()));
Assert.assertNotNull(savedLevel);
Assert.assertEquals(newTaxonomyLevelVo.getKey(), savedLevel.getKey());
Assert.assertEquals(newTaxonomyLevelVo.getParentKey(), savedLevel.getParent().getKey());
// check parent line
List<TaxonomyLevel> parentLine = taxonomyService.getTaxonomyLevelParentLine(savedLevel, taxonomy);
Assert.assertNotNull(parentLine);
Assert.assertEquals(2, parentLine.size());
Assert.assertEquals(rootLevel, parentLine.get(0));
Assert.assertEquals(savedLevel, parentLine.get(1));
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method getTaxonomyLevelTypes.
@Test
public void getTaxonomyLevelTypes() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-2", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
TaxonomyLevelType type1 = taxonomyService.createTaxonomyLevelType("RESR-Type-1", "Type 1 on rest", "Type", "EXT-Type-1", taxonomy);
TaxonomyLevelType type2 = taxonomyService.createTaxonomyLevelType("RESR-Type-2", "Type 2 on rest", "Type", "EXT-Type-2", taxonomy);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("types").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<TaxonomyLevelTypeVO> typeVoList = parseTaxonomyLevelTypesArray(response.getEntity().getContent());
Assert.assertNotNull(typeVoList);
Assert.assertEquals(2, typeVoList.size());
boolean found1 = false;
boolean found2 = false;
for (TaxonomyLevelTypeVO typeVo : typeVoList) {
if (type1.getKey().equals(typeVo.getKey())) {
found1 = true;
} else if (type2.getKey().equals(typeVo.getKey())) {
found2 = true;
}
}
Assert.assertTrue(found1);
Assert.assertTrue(found2);
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class DocumentPoolAdminPermissionsController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
List<String> names = new ArrayList<>(levelTypes.size());
for (TaxonomyLevelType levelType : levelTypes) {
EditTaxonomyLevelDocumentTypeController levelTypeCtrl = new EditTaxonomyLevelDocumentTypeController(ureq, getWindowControl(), levelType, mainForm);
listenTo(levelTypeCtrl);
String name = "perm_" + (++counter);
formLayout.add(name, levelTypeCtrl.getInitialFormItem());
typeCtrlList.add(levelTypeCtrl);
names.add(name);
}
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
layoutCont.contextPut("permissions", names);
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormSubmitButton("save", buttonsCont);
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class DocumentPoolManagerTest method hasCompetenceByTaxonomy_manage.
@Test
public void hasCompetenceByTaxonomy_manage() {
// create a level and competence with a type teach
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competent-8");
TaxonomyLevelType type = createTypeLevelCompetence(id, null, TaxonomyCompetenceTypes.manage);
// set read for teach competence
type.setDocumentsLibraryManageCompetenceEnabled(true);
type = taxonomyLevelTypeDao.updateTaxonomyLevelType(type);
dbInstance.commitAndCloseSession();
boolean hasCompetence = documentPoolManager.hasValidCompetence(id);
Assert.assertTrue(hasCompetence);
}
Aggregations