use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project OpenOLAT by OpenOLAT.
the class TaxonomyServiceImpl method cloneTaxonomyLevelType.
@Override
public TaxonomyLevelType cloneTaxonomyLevelType(TaxonomyLevelTypeRef levelType) {
TaxonomyLevelType clonedType = taxonomyLevelTypeDao.cloneTaxonomyLevelType(levelType);
List<TaxonomyLevelTypeToType> allowSubTypesToTypes = taxonomyLevelTypeToTypeDao.getAllowedSubTypes(levelType);
if (allowSubTypesToTypes.size() > 0) {
for (TaxonomyLevelTypeToType allowSubTypeToType : allowSubTypesToTypes) {
taxonomyLevelTypeToTypeDao.addAllowedSubType(clonedType, allowSubTypeToType.getAllowedSubTaxonomyLevelType());
}
}
return clonedType;
}
use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project OpenOLAT by OpenOLAT.
the class EditTaxonomyLevelController method getTypes.
private List<TaxonomyLevelType> getTypes() {
List<TaxonomyLevelType> types = new ArrayList<>();
if (level != null) {
List<TaxonomyLevel> parentLine = taxonomyService.getTaxonomyLevelParentLine(level, taxonomy);
for (int i = parentLine.size() - 1; i-- > 0; ) {
TaxonomyLevel parent = parentLine.get(i);
TaxonomyLevelType parentType = parent.getType();
if (parentType != null) {
Set<TaxonomyLevelTypeToType> typeToTypes = parentType.getAllowedTaxonomyLevelSubTypes();
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
if (typeToType != null) {
types.add(typeToType.getAllowedSubTaxonomyLevelType());
}
}
break;
}
}
}
if (types.isEmpty()) {
types.addAll(taxonomyService.getTaxonomyLevelTypes(taxonomy));
} else if (level != null && level.getType() != null) {
if (!types.contains(level.getType())) {
types.add(level.getType());
}
}
return types;
}
use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method disallowTaxonomyLevelTypeAllowedSubType.
@Test
public void disallowTaxonomyLevelTypeAllowedSubType() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-6", "Taxonomy on rest", "Rest is cool", "Ext-tax-6");
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-6", "Type 6 on rest", "Type", "EXT-Type-6", taxonomy);
TaxonomyLevelType subType1 = taxonomyService.createTaxonomyLevelType("REST-Type-6-1", "Type 6.1 on rest", "Type", "EXT-Type-6-1", taxonomy);
TaxonomyLevelType subType2 = taxonomyService.createTaxonomyLevelType("REST-Type-6-2", "Type 6.2 on rest", "Type", "EXT-Type-6-2", taxonomy);
TaxonomyLevelType subType3 = taxonomyService.createTaxonomyLevelType("REST-Type-6-3", "Type 6.3 on rest", "Type", "EXT-Type-6-3", taxonomy);
dbInstance.commit();
List<TaxonomyLevelType> allowedSubTypes = new ArrayList<>();
allowedSubTypes.add(subType1);
allowedSubTypes.add(subType2);
allowedSubTypes.add(subType3);
type = taxonomyService.updateTaxonomyLevelType(type, allowedSubTypes);
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();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
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;
boolean found3 = 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;
} else if (subType3.getKey().equals(subType.getKey())) {
found3 = true;
}
}
Assert.assertTrue(found1);
Assert.assertFalse(found2);
Assert.assertTrue(found3);
}
use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType 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.TaxonomyLevelTypeToType 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();
}
Aggregations