Search in sources :

Example 1 with AclUser

use of io.hops.hopsworks.common.dao.kafka.AclUser in project hopsworks by logicalclocks.

the class KafkaController method getTopicAclUsers.

public List<AclUser> getTopicAclUsers(Project project, String topicName) {
    if (project == null || Strings.isNullOrEmpty(topicName)) {
        throw new IllegalArgumentException("ProjectId must be non-null, topic must be provided");
    }
    List<AclUser> aclUsers = new ArrayList<>();
    List<String> teamMembers = new ArrayList<>();
    for (ProjectTeam pt : project.getProjectTeamCollection()) {
        teamMembers.add(pt.getUser().getEmail());
    }
    // wildcard used for rolebased acl
    teamMembers.add("*");
    // contains project and its members
    Map<String, List<String>> projectMemberCollections = new HashMap<>();
    projectMemberCollections.put(project.getName(), teamMembers);
    // get all the projects this topic is shared with
    List<SharedTopics> sharedTopicsList = sharedTopicsFacade.findSharedTopicsByTopicName(topicName);
    List<String> sharedMembers;
    for (SharedTopics st : sharedTopicsList) {
        sharedMembers = new ArrayList<>();
        Project p = projectFacade.find(st.getSharedTopicsPK().getProjectId());
        for (ProjectTeam pt : p.getProjectTeamCollection()) {
            sharedMembers.add(pt.getUser().getEmail());
        }
        sharedMembers.add("*");
        projectMemberCollections.put(p.getName(), sharedMembers);
    }
    for (Map.Entry<String, List<String>> user : projectMemberCollections.entrySet()) {
        aclUsers.add(new AclUser(user.getKey(), new HashSet<>(user.getValue())));
    }
    return aclUsers;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AclUser(io.hops.hopsworks.common.dao.kafka.AclUser) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with AclUser

use of io.hops.hopsworks.common.dao.kafka.AclUser in project hopsworks by logicalclocks.

the class AclBuilder method buildAclUser.

public AclUserDTO buildAclUser(UriInfo uriInfo, Project project, String topicName) {
    AclUserDTO dto = new AclUserDTO();
    URI uri = getAclUserUri(uriInfo, project, topicName).build();
    dto.setHref(uri);
    List<AclUser> list = kafkaController.getTopicAclUsers(project, topicName);
    dto.setCount(Integer.toUnsignedLong(list.size()));
    list.forEach((aclUser) -> dto.addItem(build((AclUser) aclUser)));
    return dto;
}
Also used : AclUserDTO(io.hops.hopsworks.common.dao.kafka.AclUserDTO) AclUser(io.hops.hopsworks.common.dao.kafka.AclUser) URI(java.net.URI)

Aggregations

AclUser (io.hops.hopsworks.common.dao.kafka.AclUser)2 AclUserDTO (io.hops.hopsworks.common.dao.kafka.AclUserDTO)1 SharedTopics (io.hops.hopsworks.persistence.entity.kafka.SharedTopics)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1