use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class DomainRoleEntryManagerTest method testUpdateExistingEntry.
@Test
public void testUpdateExistingEntry() {
String userId = "user";
DomainRoleEntryEntity entity = create(userId, Sets.newHashSet("domain1", "domain2"), Role.OWNER);
flushAndClear();
DomainRoleEntry updatedEntry = new DomainRoleEntry(userId, new String[] { "domain3" }, Role.OWNER);
CreateOrUpdateResult<DomainRoleEntry> result = subject.createOrUpdate(updatedEntry);
flushAndClear();
assertNotNull(result);
assertEquals(ChangeType.UPDATE, result.getChangeType());
assertEquals(userId, result.getEntry().getUid());
assertEquals(Role.OWNER, result.getEntry().getRole());
assertNotNull(result.getEntry().getRole());
assertEquals(1, result.getEntry().getDomains().length);
assertEquals("domain3", result.getEntry().getDomains()[0]);
}
use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class DomainRoleEntryManager method findByUserId.
public DomainRoleEntry[] findByUserId(String userId) {
Query query = entityManager.createQuery("select dre from DomainRoleEntryEntity dre where dre.userId = :userId", DomainRoleEntryEntity.class);
query.setParameter("userId", userId);
List<DomainRoleEntryEntity> entities = query.getResultList();
Set<DomainRoleEntry> resultSet = entities.stream().map(this::mapEntityToJoynrType).collect(toSet());
return resultSet.toArray(new DomainRoleEntry[resultSet.size()]);
}
use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class DomainRoleEntryManager method findByUserIdAndRole.
private DomainRoleEntryEntity findByUserIdAndRole(String userId, Role role) {
Query query = entityManager.createQuery("select dre from DomainRoleEntryEntity dre where dre.userId = :userId and dre.role = :role", DomainRoleEntryEntity.class);
query.setParameter("userId", userId);
query.setParameter("role", role);
List<DomainRoleEntryEntity> resultList = query.getResultList();
if (resultList.size() == 1) {
return resultList.get(0);
} else if (resultList.size() > 1) {
throw new IllegalStateException("Too many entries found for DomainRoleEntryEntity with user id " + userId + " and role " + role);
}
return null;
}
use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class DomainRoleEntryManager method createOrUpdate.
public CreateOrUpdateResult<DomainRoleEntry> createOrUpdate(DomainRoleEntry joynrType) {
DomainRoleEntryEntity entity = findByUserIdAndRole(joynrType.getUid(), joynrType.getRole());
boolean created = entity == null;
if (!created) {
entity.getDomains().clear();
entity.getDomains().addAll(Sets.newHashSet(joynrType.getDomains()));
} else {
entity = mapJoynrTypeToEntity(joynrType);
entityManager.persist(entity);
}
return new CreateOrUpdateResult<>(mapEntityToJoynrType(entity), created ? ChangeType.ADD : ChangeType.UPDATE);
}
use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class DomainRoleEntryManager method mapJoynrTypeToEntity.
private DomainRoleEntryEntity mapJoynrTypeToEntity(DomainRoleEntry joynrType) {
DomainRoleEntryEntity result = new DomainRoleEntryEntity();
result.setUserId(joynrType.getUid());
result.setDomains(Sets.newHashSet(joynrType.getDomains()));
result.setRole(joynrType.getRole());
return result;
}
Aggregations