Search in sources :

Example 11 with DomainRoleEntryEntity

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]);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Test(org.junit.Test)

Example 12 with DomainRoleEntryEntity

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()]);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) Query(javax.persistence.Query) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry)

Example 13 with DomainRoleEntryEntity

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;
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) Query(javax.persistence.Query)

Example 14 with DomainRoleEntryEntity

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);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)

Example 15 with DomainRoleEntryEntity

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;
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)

Aggregations

DomainRoleEntryEntity (io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)15 Test (org.junit.Test)9 Query (javax.persistence.Query)2 DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)2 MasterAccessControlEntry (joynr.infrastructure.DacTypes.MasterAccessControlEntry)2 MasterRegistrationControlEntry (joynr.infrastructure.DacTypes.MasterRegistrationControlEntry)2 OwnerAccessControlEntry (joynr.infrastructure.DacTypes.OwnerAccessControlEntry)2 OwnerRegistrationControlEntry (joynr.infrastructure.DacTypes.OwnerRegistrationControlEntry)2