Search in sources :

Example 11 with TaxonomyLevelTypeRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl in project openolat by klemens.

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)

Example 12 with TaxonomyLevelTypeRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl in project openolat by klemens.

the class TaxonomyWebService method disalloweSubTaxonomyLevelType.

/**
 * Remove a sub-type to a specified taxonomy level's type.
 *
 * @response.representation.200.doc The sub type was removed sucessfully
 * @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 typeKey The type
 * @param subTypeKey The sub type to remove
 * @param httpRequest  The HTTP request
 * @return Nothing
 */
@DELETE
@Path("types/{typeKey}/allowedSubTypes/{subTypeKey}")
public Response disalloweSubTaxonomyLevelType(@PathParam("typeKey") Long typeKey, @PathParam("subTypeKey") Long subTypeKey) {
    TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(typeKey));
    TaxonomyLevelType subType = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(subTypeKey));
    if (type == null || subType == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    taxonomyService.taxonomyLevelTypeDisallowSubType(type, subType);
    return Response.ok().build();
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 13 with TaxonomyLevelTypeRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl in project openolat by klemens.

the class TaxonomyWebService method putTaxonomyLevel.

/**
 * Create or update a taxonomy level. The method changes to tree structure, a
 * null parent key will make the level a root one, a new parent key will move
 * the level.
 *
 * @response.representation.200.qname {http://www.example.com}taxonomyLevelVO
 * @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_TAXONOMYLEVELVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc An existant level was not found
 * @param taxonomyKey The taxonomy tree where this level is
 * @param httpRequest  The HTTP request
 * @param levelVo The roll call to update
 * @return The updated roll call
 */
@PUT
@Path("levels")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response putTaxonomyLevel(TaxonomyLevelVO levelVo) {
    TaxonomyLevel parentLevel = null;
    if (levelVo.getParentKey() != null) {
        parentLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getParentKey()));
    }
    TaxonomyLevel level;
    if (levelVo.getKey() != null) {
        level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getKey()));
        if (levelVo.getIdentifier() != null) {
            level.setIdentifier(levelVo.getIdentifier());
        }
        if (levelVo.getDisplayName() != null) {
            level.setDisplayName(levelVo.getDisplayName());
        }
        if (levelVo.getDescription() != null) {
            level.setDescription(levelVo.getDescription());
        }
        if (levelVo.getExternalId() != null) {
            level.setExternalId(levelVo.getExternalId());
        }
        if (levelVo.getTypeKey() != null) {
            TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(levelVo.getTypeKey()));
            level.setType(type);
        }
        if (levelVo.getManagedFlags() != null) {
            level.setManagedFlags(TaxonomyLevelManagedFlag.toEnum(levelVo.getManagedFlags()));
        }
        level = taxonomyService.updateTaxonomyLevel(level);
    } else {
        level = taxonomyService.createTaxonomyLevel(levelVo.getIdentifier(), levelVo.getDisplayName(), levelVo.getDescription(), levelVo.getExternalId(), TaxonomyLevelManagedFlag.toEnum(levelVo.getManagedFlags()), parentLevel, taxonomy);
        if (levelVo.getTypeKey() != null) {
            TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(levelVo.getTypeKey()));
            level.setType(type);
            level = taxonomyService.updateTaxonomyLevel(level);
        }
    }
    if ((level.getParent() != null && levelVo.getParentKey() == null) || (level.getParent() == null && levelVo.getParentKey() != null) || (level.getParent() != null && !level.getParent().getKey().equals(levelVo.getParentKey()))) {
        TaxonomyLevel newParentLevel = null;
        if (levelVo.getParentKey() != null) {
            newParentLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getParentKey()));
        }
        level = taxonomyService.moveTaxonomyLevel(level, newParentLevel);
    }
    TaxonomyLevelVO newLevelVo = new TaxonomyLevelVO(level);
    return Response.ok(newLevelVo).build();
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 14 with TaxonomyLevelTypeRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl in project openolat by klemens.

the class TypeTaxonomyLevelController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String selectedTypeKey = typeEl.getSelectedKey();
    TaxonomyLevelType selectedType = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(Long.valueOf(selectedTypeKey)));
    for (TaxonomyLevel level : levels) {
        level.setType(selectedType);
        level = taxonomyService.updateTaxonomyLevel(level);
    }
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)

Aggregations

TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)14 TaxonomyLevelTypeRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)14 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)8 PUT (javax.ws.rs.PUT)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 Consumes (javax.ws.rs.Consumes)4 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)4 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 TaxonomyLevelRef (org.olat.modules.taxonomy.TaxonomyLevelRef)2 TaxonomyLevelTypeRef (org.olat.modules.taxonomy.TaxonomyLevelTypeRef)2 TaxonomyLevelTypeToType (org.olat.modules.taxonomy.TaxonomyLevelTypeToType)2