@Test public void fromExternalUser() { Map<String, Object> attributes = new HashMap<>(); attributes.put(SKILLS_ATTRIBUTE, String.format("%s, %s,%s", SKILL2, SKILL1, SKILL3)); attributes.put(AFFINITIES_ATTRIBUTE, String.format(" %s, %s", AFFINITY2, AFFINITY1)); attributes.put(ANOTHER__ATTRIBUTE, "someValue"); org.kie.server.services.taskassigning.user.system.api.User externalUser = mockUser(USER_ID_1, attributes); org.kie.server.services.taskassigning.user.system.api.Group externalGroup1 = mockExternalGroup(GROUP1_ID); org.kie.server.services.taskassigning.user.system.api.Group externalGroup2 = mockExternalGroup(GROUP2_ID); org.kie.server.services.taskassigning.user.system.api.Group externalGroup3 = mockExternalGroup(GROUP3_ID); Set<org.kie.server.services.taskassigning.user.system.api.Group> externalGroups = new HashSet<>(); externalGroups.add(externalGroup1); externalGroups.add(externalGroup2); externalGroups.add(externalGroup3); when(externalUser.getGroups()).thenReturn(externalGroups); User user = UserUtil.fromExternalUser(externalUser); assertEquals(USER_ID_1.hashCode(), user.getId(), 0); assertEquals(USER_ID_1, user.getEntityId()); assertTrue(user.isEnabled()); assertEquals(user.getGroups().size(), externalGroups.size()); assertContains(GROUP1_ID, user.getGroups()); assertContains(GROUP2_ID, user.getGroups()); assertContains(GROUP3_ID, user.getGroups()); assertEquals(new HashSet<>(Arrays.asList(SKILL3, SKILL2, SKILL1)), user.getLabelValues(SKILLS.name())); assertEquals(new HashSet<>(Arrays.asList(AFFINITY1, AFFINITY2)), user.getLabelValues(AFFINITIES.name())); assertEquals(attributes, user.getAttributes()); }
public static User fromExternalUser(org.kie.server.services.taskassigning.user.system.api.User externalUser) { final User user = new User(externalUser.getId().hashCode(), externalUser.getId(), true); final Set<Group> groups = new HashSet<>(); user.setGroups(groups); if (externalUser.getGroups() != null) { externalUser.getGroups().forEach(externalGroup -> groups.add(new Group(externalGroup.getId().hashCode(), externalGroup.getId()))); } user.setAttributes(externalUser.getAttributes()); LabelValueExtractorRegistry.getInstance() .applyLabelValueExtractors(org.kie.server.services.taskassigning.user.system.api.User.class, externalUser, user::setLabelValues); return user; }
UserUtil { public static User fromExternalUser(org.kie.server.services.taskassigning.user.system.api.User externalUser) { final User user = new User(externalUser.getId().hashCode(), externalUser.getId(), true); final Set<Group> groups = new HashSet<>(); user.setGroups(groups); if (externalUser.getGroups() != null) { externalUser.getGroups().forEach(externalGroup -> groups.add(new Group(externalGroup.getId().hashCode(), externalGroup.getId()))); } user.setAttributes(externalUser.getAttributes()); LabelValueExtractorRegistry.getInstance() .applyLabelValueExtractors(org.kie.server.services.taskassigning.user.system.api.User.class, externalUser, user::setLabelValues); return user; } }
UserUtil { public static User fromExternalUser(org.kie.server.services.taskassigning.user.system.api.User externalUser) { final User user = new User(externalUser.getId().hashCode(), externalUser.getId(), true); final Set<Group> groups = new HashSet<>(); user.setGroups(groups); if (externalUser.getGroups() != null) { externalUser.getGroups().forEach(externalGroup -> groups.add(new Group(externalGroup.getId().hashCode(), externalGroup.getId()))); } user.setAttributes(externalUser.getAttributes()); LabelValueExtractorRegistry.getInstance() .applyLabelValueExtractors(org.kie.server.services.taskassigning.user.system.api.User.class, externalUser, user::setLabelValues); return user; } private  UserUtil(); }
UserUtil { public static User fromExternalUser(org.kie.server.services.taskassigning.user.system.api.User externalUser) { final User user = new User(externalUser.getId().hashCode(), externalUser.getId(), true); final Set<Group> groups = new HashSet<>(); user.setGroups(groups); if (externalUser.getGroups() != null) { externalUser.getGroups().forEach(externalGroup -> groups.add(new Group(externalGroup.getId().hashCode(), externalGroup.getId()))); } user.setAttributes(externalUser.getAttributes()); LabelValueExtractorRegistry.getInstance() .applyLabelValueExtractors(org.kie.server.services.taskassigning.user.system.api.User.class, externalUser, user::setLabelValues); return user; } private  UserUtil(); static User fromExternalUser(org.kie.server.services.taskassigning.user.system.api.User externalUser); static boolean isUser(String userType); static Stream<org.kie.server.services.taskassigning.user.system.api.User> filterDuplicates(Collection<org.kie.server.services.taskassigning.user.system.api.User> externalUsers); }
UserUtil { public static User fromExternalUser(org.kie.server.services.taskassigning.user.system.api.User externalUser) { final User user = new User(externalUser.getId().hashCode(), externalUser.getId(), true); final Set<Group> groups = new HashSet<>(); user.setGroups(groups); if (externalUser.getGroups() != null) { externalUser.getGroups().forEach(externalGroup -> groups.add(new Group(externalGroup.getId().hashCode(), externalGroup.getId()))); } user.setAttributes(externalUser.getAttributes()); LabelValueExtractorRegistry.getInstance() .applyLabelValueExtractors(org.kie.server.services.taskassigning.user.system.api.User.class, externalUser, user::setLabelValues); return user; } private  UserUtil(); static User fromExternalUser(org.kie.server.services.taskassigning.user.system.api.User externalUser); static boolean isUser(String userType); static Stream<org.kie.server.services.taskassigning.user.system.api.User> filterDuplicates(Collection<org.kie.server.services.taskassigning.user.system.api.User> externalUsers);  }