Search in sources :

Example 16 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class DelegateOrgResourceTest method createDelegateCompanyReceiverGroup.

@Test
public void createDelegateCompanyReceiverGroup() {
    initSpringSecurityContext("mtuyer");
    final DelegateOrgEditionVo vo = new DelegateOrgEditionVo();
    vo.setName("ing");
    vo.setType(DelegateType.COMPANY);
    vo.setReceiver("DIG");
    vo.setReceiverType(ReceiverType.GROUP);
    vo.setCanAdmin(true);
    final int id = resource.create(vo);
    em.flush();
    em.clear();
    final DelegateOrg entity = repository.findOneExpected(id);
    Assertions.assertEquals("ing", entity.getName());
    Assertions.assertEquals("ou=ing,ou=external,ou=people,dc=sample,dc=com", entity.getDn());
    Assertions.assertEquals(DelegateType.COMPANY, entity.getType());
    Assertions.assertEquals("mtuyer", entity.getCreatedBy());
    Assertions.assertEquals("dig", entity.getReceiver());
    Assertions.assertEquals(ReceiverType.GROUP, entity.getReceiverType());
    Assertions.assertEquals("cn=dig,ou=fonction,ou=groups,dc=sample,dc=com", entity.getReceiverDn());
    Assertions.assertTrue(entity.isCanAdmin());
}
Also used : DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest) Test(org.junit.jupiter.api.Test)

Example 17 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class DelegateOrgResourceTest method updateNoChange.

@Test
public void updateNoChange() {
    initSpringSecurityContext("mtuyer");
    final DelegateOrgEditionVo vo = new DelegateOrgEditionVo();
    // Add space that would be trimmed
    vo.setName("ou=fonction,ou=groups,dc=sample,dc=com  ");
    vo.setReceiver("mtuyer");
    vo.setCanWrite(true);
    final DelegateOrg entity = updateNoChangeBase("mtuyer", vo);
    Assertions.assertTrue(entity.isCanWrite());
    Assertions.assertTrue(entity.isCanAdmin());
}
Also used : DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest) Test(org.junit.jupiter.api.Test)

Example 18 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class DelegateOrgResource method findAll.

/**
 * Retrieve all elements with pagination
 *
 * @param uriInfo
 *            pagination data.
 * @param typeSearch
 *            Optional {@link DelegateType} search.
 * @return all elements with pagination.
 */
@GET
public TableItem<DelegateOrgLightVo> findAll(@Context final UriInfo uriInfo, @QueryParam("type") final DelegateType typeSearch) {
    // Trigger cache loading
    getUser().findAll();
    final PageRequest pageRequest = paginationJson.getPageRequest(uriInfo, ORDERED_COLUMNS);
    final Page<DelegateOrg> findAll = repository.findAll(securityHelper.getLogin(), DataTableAttributes.getSearch(uriInfo), typeSearch, pageRequest);
    // apply pagination and prevent lazy initialization issue
    return paginationJson.applyPagination(uriInfo, findAll, this::toVo);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) GET(javax.ws.rs.GET)

Example 19 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class DelegateOrgResource method toEntity.

/**
 * Build the entity from the import entry.
 *
 * @param importEntry
 *            The new delegate.
 * @return The JPA entity form with validated inputs.
 */
private DelegateOrg toEntity(final DelegateOrgEditionVo importEntry) {
    // Validate the related receiver of this delegate
    final ResourceOrg receiver = toReceiver.get(importEntry.getReceiverType()).apply(importEntry.getReceiver());
    final DelegateOrg entity = new DelegateOrg();
    entity.setId(importEntry.getId());
    entity.setName(Normalizer.normalize(importEntry.getName()));
    entity.setCanAdmin(importEntry.isCanAdmin());
    entity.setCanWrite(importEntry.isCanWrite());
    entity.setType(importEntry.getType());
    entity.setReceiver(receiver.getId());
    entity.setReceiverType(importEntry.getReceiverType());
    if (receiver instanceof ContainerOrg) {
        // Store receiver DN only for immutable containers
        entity.setReceiverDn(receiver.getDn());
    }
    return entity;
}
Also used : ContainerOrg(org.ligoj.app.iam.ContainerOrg) DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) ResourceOrg(org.ligoj.app.iam.ResourceOrg)

Aggregations

DelegateOrg (org.ligoj.app.iam.model.DelegateOrg)19 Test (org.junit.jupiter.api.Test)13 AbstractOrgTest (org.ligoj.app.resource.AbstractOrgTest)13 ForbiddenException (javax.ws.rs.ForbiddenException)2 GET (javax.ws.rs.GET)1 UriInfo (javax.ws.rs.core.UriInfo)1 CompanyOrg (org.ligoj.app.iam.CompanyOrg)1 ContainerOrg (org.ligoj.app.iam.ContainerOrg)1 GroupOrg (org.ligoj.app.iam.GroupOrg)1 ResourceOrg (org.ligoj.app.iam.ResourceOrg)1 CacheGroup (org.ligoj.app.iam.model.CacheGroup)1 CacheMembership (org.ligoj.app.iam.model.CacheMembership)1 CacheUser (org.ligoj.app.iam.model.CacheUser)1 CacheProjectGroup (org.ligoj.app.model.CacheProjectGroup)1 PageRequest (org.springframework.data.domain.PageRequest)1