use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl in project OpenOLAT by OpenOLAT.
the class TaxonomyLevelLibraryIndexer method checkAccess.
@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
if (roles.isOLATAdmin())
return true;
if ("TaxonomyLevel".equals(contextEntry.getOLATResourceable().getResourceableTypeName())) {
Long levelKey = contextEntry.getOLATResourceable().getResourceableId();
TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelKey));
TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(level.getTaxonomy(), identity, null, false, true, "Templates", null);
TreeModel model = builder.buildTreeModel();
List<TreeNode> flat = new ArrayList<>();
TreeHelper.makeTreeFlat(model.getRootNode(), flat);
for (TreeNode node : flat) {
TaxonomyTreeNode taxonomyNode = (TaxonomyTreeNode) node;
if (taxonomyNode.getType() == TaxonomyTreeNodeType.taxonomyLevel && level.equals(taxonomyNode.getTaxonomyLevel())) {
if (taxonomyNode.isDocumentsLibraryEnabled() && taxonomyNode.isCanRead()) {
return true;
}
}
}
}
return false;
}
use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method deleteTaxonomyLevel.
@Test
public void deleteTaxonomyLevel() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Del-1", "Taxonomy on rest", "Delete is sad!", "DELETE-tax-1");
TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Del-root", "Root level on rest", "Level", "Ext-55", null, null, taxonomy);
TaxonomyLevel levelToDelete = taxonomyService.createTaxonomyLevel("REST-Del-u-1", "Sub level on rest", "Level", "Ext-56", null, rootLevel, 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("levels").path(levelToDelete.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());
// check the deleted value
TaxonomyLevel deletedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelToDelete.getKey()));
Assert.assertNull(deletedLevel);
TaxonomyLevel survivingRootLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(rootLevel.getKey()));
Assert.assertNotNull(survivingRootLevel);
}
use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method updateTaxonomyLevel.
/**
* Update level.
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void updateTaxonomyLevel() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-4", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Tax-u-1", "Root level on rest", "Level", "Ext-25", null, null, taxonomy);
TaxonomyLevel levelToUpdate = taxonomyService.createTaxonomyLevel("REST-Tax-u-1", "Sub level on rest", "Level", "Ext-26", null, rootLevel, taxonomy);
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("Sub-type", "Type for a sub level", "All is in the title", "TYP-27", taxonomy);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
TaxonomyLevelVO levelVo = new TaxonomyLevelVO();
levelVo.setKey(levelToUpdate.getKey());
levelVo.setIdentifier("Updated id");
levelVo.setDisplayName("Updated name");
levelVo.setDescription("Updated description");
levelVo.setExternalId("Updated ext.");
levelVo.setTypeKey(type.getKey());
levelVo.setParentKey(rootLevel.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 updated value
TaxonomyLevelVO updatedTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
Assert.assertNotNull(updatedTaxonomyLevelVo);
Assert.assertEquals("Updated id", updatedTaxonomyLevelVo.getIdentifier());
Assert.assertEquals("Updated name", updatedTaxonomyLevelVo.getDisplayName());
Assert.assertEquals("Updated description", updatedTaxonomyLevelVo.getDescription());
Assert.assertEquals("Updated ext.", updatedTaxonomyLevelVo.getExternalId());
Assert.assertEquals(rootLevel.getKey(), updatedTaxonomyLevelVo.getParentKey());
Assert.assertEquals(type.getKey(), updatedTaxonomyLevelVo.getTypeKey());
// check the database
TaxonomyLevel savedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(updatedTaxonomyLevelVo.getKey()));
Assert.assertNotNull(savedLevel);
Assert.assertEquals("Updated id", savedLevel.getIdentifier());
Assert.assertEquals("Updated name", savedLevel.getDisplayName());
Assert.assertEquals("Updated description", savedLevel.getDescription());
Assert.assertEquals("Updated ext.", savedLevel.getExternalId());
Assert.assertEquals(rootLevel.getKey(), savedLevel.getParent().getKey());
Assert.assertEquals(type.getKey(), savedLevel.getType().getKey());
}
use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl in project OpenOLAT by OpenOLAT.
the class TaxonomyWebService method addTaxonomyLevelComptencesByIdentity.
private Response addTaxonomyLevelComptencesByIdentity(Long taxonomyLevelKey, TaxonomyCompetenceVO comptenceVo, Identity executor) {
if (taxonomyLevelKey != null && comptenceVo.getTaxonomyLevelKey() != null && !taxonomyLevelKey.equals(comptenceVo.getTaxonomyLevelKey())) {
return Response.serverError().status(Status.CONFLICT).build();
}
if (taxonomyLevelKey == null) {
taxonomyLevelKey = comptenceVo.getTaxonomyLevelKey();
}
TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
if (level == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity identity = securityManager.loadIdentityByKey(comptenceVo.getIdentityKey());
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
TaxonomyCompetence competence = null;
List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level, identity);
for (TaxonomyCompetence c : competences) {
if (c.getCompetenceType().name().equals(comptenceVo.getTaxonomyCompetenceType())) {
competence = c;
}
}
if (competence == null) {
TaxonomyCompetenceTypes competenceType = TaxonomyCompetenceTypes.valueOf(comptenceVo.getTaxonomyCompetenceType());
competence = taxonomyService.addTaxonomyLevelCompetences(level, identity, competenceType, comptenceVo.getExpiration());
} else {
competence.setExpiration(comptenceVo.getExpiration());
competence = taxonomyService.updateTaxonomyLevelCompetence(competence);
}
String after = taxonomyService.toAuditXml(competence);
taxonomyService.auditLog(TaxonomyCompetenceAuditLog.Action.addCompetence, null, after, null, taxonomy, competence, identity, executor);
return Response.ok(new TaxonomyCompetenceVO(competence)).build();
}
use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl in project OpenOLAT by OpenOLAT.
the class TaxonomyWebService method getTaxonomyLevelComptencesByIdentity.
/**
* Return the competences of a specific user on the taxonomy level
* specified in the key in path.
*
* @response.representation.200.qname {http://www.example.com}taxonomyCompetenceVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc An array of competences
* @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYCOMPETENCEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param taxonomyKey The taxonomy tree
* @param taxonomyLevelKey The level of the taxonomy
* @param identityKey The user
* @param httpRequest The HTTP request
* @return An array of competences
*/
@GET
@Path("levels/{taxonomyLevelKey}/competences/{identityKey}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaxonomyLevelComptencesByIdentity(@PathParam("taxonomyLevelKey") Long taxonomyLevelKey, @PathParam("identityKey") Long identityKey) {
TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
if (level == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity identity = securityManager.loadIdentityByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level, identity);
List<TaxonomyCompetenceVO> competenceVOes = new ArrayList<>(competences.size());
for (TaxonomyCompetence competence : competences) {
competenceVOes.add(new TaxonomyCompetenceVO(competence));
}
return Response.ok(competenceVOes.toArray(new TaxonomyCompetenceVO[competenceVOes.size()])).build();
}
Aggregations