Search in sources :

Example 6 with MasterAccessControlEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity in project joynr by bmwcarit.

the class MasterAccessControlEntryManager method findByUserIdDomainInterfaceNameOperationAndType.

private MasterAccessControlEntryEntity findByUserIdDomainInterfaceNameOperationAndType(String userId, String domain, String interfaceName, String operation, ControlEntryType type) {
    Query query = entityManager.createQuery("select mace from MasterAccessControlEntryEntity mace " + "where mace.userId = :userId and mace.domain = :domain and mace.interfaceName = :interfaceName " + "and mace.operation = :operation and mace.type = :type", MasterAccessControlEntryEntity.class);
    query.setParameter("userId", userId);
    query.setParameter("domain", domain);
    query.setParameter("interfaceName", interfaceName);
    query.setParameter("operation", operation);
    query.setParameter("type", type);
    List<MasterAccessControlEntryEntity> resultList = query.getResultList();
    MasterAccessControlEntryEntity entity = null;
    if (resultList.size() == 1) {
        entity = resultList.get(0);
    } else if (resultList.size() > 1) {
        throw new JoynrIllegalStateException(format("Too many master access control entries for unique key uid / domain / interfaceName /operation: %s / %s / %s / %s", userId, domain, interfaceName, operation));
    }
    return entity;
}
Also used : MasterAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity) Query(javax.persistence.Query) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 7 with MasterAccessControlEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity in project joynr by bmwcarit.

the class MasterAccessControlEntryManager method findByUserIdThatAreEditable.

public MasterAccessControlEntry[] findByUserIdThatAreEditable(String userId, ControlEntryType type) {
    Query query = entityManager.createQuery("select mace from MasterAccessControlEntryEntity mace, " + "DomainRoleEntryEntity dre, in(dre.domains) dds where mace.userId = :userId and mace.type = :type " + "and mace.domain = dds and dre.userId = :userId and dre.role = :role");
    query.setParameter("userId", userId);
    query.setParameter("type", type);
    query.setParameter("role", Role.MASTER);
    List<MasterAccessControlEntryEntity> resultList = query.getResultList();
    Set<MasterAccessControlEntry> resultSet = resultList.stream().map(this::mapEntityToJoynrType).collect(toSet());
    return resultSet.toArray(new MasterAccessControlEntry[resultSet.size()]);
}
Also used : MasterAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity) Query(javax.persistence.Query) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry)

Example 8 with MasterAccessControlEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity in project joynr by bmwcarit.

the class MasterAccessControlEntryManager method findByUserId.

public MasterAccessControlEntry[] findByUserId(String userId, ControlEntryType type) {
    Query query = entityManager.createQuery("select mace from MasterAccessControlEntryEntity mace where mace.userId = :userId and mace.type = :type", MasterAccessControlEntryEntity.class);
    query.setParameter("userId", userId);
    query.setParameter("type", type);
    List<MasterAccessControlEntryEntity> resultList = query.getResultList();
    Set<MasterAccessControlEntry> resultSet = resultList.stream().map(this::mapEntityToJoynrType).collect(toSet());
    return resultSet.toArray(new MasterAccessControlEntry[resultSet.size()]);
}
Also used : MasterAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity) Query(javax.persistence.Query) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry)

Aggregations

MasterAccessControlEntryEntity (io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity)8 MasterAccessControlEntry (joynr.infrastructure.DacTypes.MasterAccessControlEntry)5 Query (javax.persistence.Query)4 Test (org.junit.Test)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1