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());
}
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());
}
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);
}
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;
}
Aggregations