use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyLevelTypeDAOTest method allowSubTypes.
@Test
public void allowSubTypes() {
Taxonomy taxonomy = taxonomyDao.createTaxonomy("Tax-type", "Typed taxonomy", "A typed taxonomy", "");
TaxonomyLevelType type = taxonomyLevelTypeDao.createTaxonomyLevelType("Type-parent", "A type", null, null, taxonomy);
TaxonomyLevelType subType1 = taxonomyLevelTypeDao.createTaxonomyLevelType("Type-sub-1", "A type", null, null, taxonomy);
TaxonomyLevelType subType2 = taxonomyLevelTypeDao.createTaxonomyLevelType("Type-sub-2", "A type", null, null, taxonomy);
dbInstance.commitAndCloseSession();
taxonomyLevelTypeToTypeDao.addAllowedSubType(type, subType1);
taxonomyLevelTypeToTypeDao.addAllowedSubType(type, subType2);
dbInstance.commitAndCloseSession();
TaxonomyLevelTypeImpl reloadedType = (TaxonomyLevelTypeImpl) taxonomyLevelTypeDao.loadTaxonomyLevelTypeByKey(type.getKey());
Assert.assertNotNull(reloadedType.getAllowedTaxonomyLevelSubTypes());
Assert.assertEquals(2, reloadedType.getAllowedTaxonomyLevelSubTypes().size());
Set<TaxonomyLevelTypeToType> allowedTypeSet = reloadedType.getAllowedTaxonomyLevelSubTypes();
List<TaxonomyLevelType> allowedSubTypes = allowedTypeSet.stream().map(t -> t.getAllowedSubTaxonomyLevelType()).collect(Collectors.toList());
Assert.assertTrue(allowedSubTypes.contains(subType1));
Assert.assertTrue(allowedSubTypes.contains(subType2));
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyLevelTypeDAOTest method loadTaxonomyLevelTypeByTaxonomy.
@Test
public void loadTaxonomyLevelTypeByTaxonomy() {
Taxonomy taxonomy = taxonomyDao.createTaxonomy("Tax-type", "Typed taxonomy", "A typed taxonomy", "");
Taxonomy taxonomyMarker = taxonomyDao.createTaxonomy("Tax-marker", "Marker taxonomy", "An unused taxonomy", "");
TaxonomyLevelType type = taxonomyLevelTypeDao.createTaxonomyLevelType("Type-reload", "A first reloaded type", "Typed", "TYP-1", taxonomy);
dbInstance.commitAndCloseSession();
// check the taxonomy with types
List<TaxonomyLevelType> taxonomyTypes = taxonomyLevelTypeDao.loadTaxonomyLevelTypeByTaxonomy(taxonomy);
Assert.assertNotNull(taxonomyTypes);
Assert.assertEquals(1, taxonomyTypes.size());
Assert.assertEquals(type, taxonomyTypes.get(0));
// check the marker without
List<TaxonomyLevelType> taxonomyWithoutTypes = taxonomyLevelTypeDao.loadTaxonomyLevelTypeByTaxonomy(taxonomyMarker);
Assert.assertNotNull(taxonomyWithoutTypes);
Assert.assertEquals(0, taxonomyWithoutTypes.size());
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebService method getTaxonomyLevelTypes.
/**
* Get the configurations for taxonomy levels for the whole taxonomy.
*
* @response.representation.200.qname {http://www.example.com}taxonomyLevelTypeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc A taxonomy level
* @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYLEVELTYPEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The taxonomy was not found
* @param taxonomyKey The taxonomy tree
* @param httpRequest The HTTP request
* @return An array of taxonomy levels types
*/
@GET
@Path("types")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaxonomyLevelTypes() {
List<TaxonomyLevelType> types = taxonomyService.getTaxonomyLevelTypes(taxonomy);
List<TaxonomyLevelTypeVO> typeVOes = new ArrayList<>(types.size());
for (TaxonomyLevelType type : types) {
typeVOes.add(new TaxonomyLevelTypeVO(type));
}
return Response.ok(typeVOes.toArray(new TaxonomyLevelTypeVO[typeVOes.size()])).build();
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebService method getAllowedSubTaxonomyLevelTypes.
/**
* Get the allowed sub-types of a specified taxonomy level's type.
*
* @response.representation.200.qname {http://www.example.com}taxonomyLevelTypeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc An array of taxonomy level types
* @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYLEVELTYPEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The taxonomy level type was not found
* @param taxonomyKey The taxonomy tree
* @param httpRequest The HTTP request
* @param typeKey The primary key of the taxonomy level type
* @return An array of taxonomy level types
*/
@GET
@Path("types/{typeKey}/allowedSubTypes")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAllowedSubTaxonomyLevelTypes(@PathParam("typeKey") Long typeKey) {
TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(typeKey));
if (type == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Set<TaxonomyLevelTypeToType> typeToTypes = type.getAllowedTaxonomyLevelSubTypes();
List<TaxonomyLevelTypeVO> subTypeVOes = new ArrayList<>(typeToTypes.size());
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
TaxonomyLevelType subType = typeToType.getAllowedSubTaxonomyLevelType();
subTypeVOes.add(new TaxonomyLevelTypeVO(subType));
}
return Response.ok(subTypeVOes.toArray(new TaxonomyLevelTypeVO[subTypeVOes.size()])).build();
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class MoveTaxonomyLevelController method getAllowedTypes.
private Set<TaxonomyLevelType> getAllowedTypes() {
List<TaxonomyLevelType> allTypes = new ArrayList<>(taxonomyService.getTaxonomyLevelTypes(taxonomy));
Map<TaxonomyLevelType, Set<TaxonomyLevelType>> subToParentTypes = new HashMap<>();
for (TaxonomyLevelType type : allTypes) {
Set<TaxonomyLevelTypeToType> typesToTypes = type.getAllowedTaxonomyLevelSubTypes();
for (TaxonomyLevelTypeToType typeToType : typesToTypes) {
TaxonomyLevelType subTyp = typeToType.getAllowedSubTaxonomyLevelType();
subToParentTypes.computeIfAbsent(subTyp, t -> new HashSet<>()).add(type);
}
}
Set<TaxonomyLevelType> analyzedTypes = new HashSet<>();
for (TaxonomyLevel level : levelsToMove) {
TaxonomyLevelType levelType = level.getType();
if (levelType != null && !analyzedTypes.contains(levelType)) {
analyzedTypes.add(levelType);
Set<TaxonomyLevelType> allowed = subToParentTypes.get(levelType);
if (allowed != null) {
allTypes.retainAll(allowed);
}
}
}
return new HashSet<>(allTypes);
}
Aggregations