Search in sources :

Example 1 with TaxonomyLevelTypeToType

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;
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType)

Example 2 with TaxonomyLevelTypeToType

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;
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType)

Example 3 with TaxonomyLevelTypeToType

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);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) URI(java.net.URI) Test(org.junit.Test)

Example 4 with TaxonomyLevelTypeToType

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));
}
Also used : TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) List(java.util.List) DB(org.olat.core.commons.persistence.DB) TaxonomyLevelTypeImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeImpl) Set(java.util.Set) OlatTestCase(org.olat.test.OlatTestCase) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) Assert(org.junit.Assert) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) Collectors(java.util.stream.Collectors) Taxonomy(org.olat.modules.taxonomy.Taxonomy) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) TaxonomyLevelTypeImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeImpl) Test(org.junit.Test)

Example 5 with TaxonomyLevelTypeToType

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();
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) ArrayList(java.util.ArrayList) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

TaxonomyLevelTypeToType (org.olat.modules.taxonomy.TaxonomyLevelTypeToType)18 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)16 ArrayList (java.util.ArrayList)10 Taxonomy (org.olat.modules.taxonomy.Taxonomy)8 Test (org.junit.Test)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 URI (java.net.URI)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 HttpResponse (org.apache.http.HttpResponse)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPut (org.apache.http.client.methods.HttpPut)2