use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjb method deleteSamples.
public List<String> deleteSamples(List<String> sampleUuids) {
User user = userService.getCurrentUser();
if (!userRoleConfigFacade.getEffectiveUserRights(user.getUserRoles().toArray(new UserRole[user.getUserRoles().size()])).contains(UserRight.SAMPLE_DELETE)) {
throw new UnsupportedOperationException("User " + user.getUuid() + " is not allowed to delete samples.");
}
List<String> deletedSampleUuids = new ArrayList<>();
List<Sample> samplesToBeDeleted = sampleService.getByUuids(sampleUuids);
if (samplesToBeDeleted != null) {
samplesToBeDeleted.forEach(sampleToBeDeleted -> {
if (!sampleToBeDeleted.isDeleted()) {
sampleService.delete(sampleToBeDeleted);
deletedSampleUuids.add(sampleToBeDeleted.getUuid());
}
});
}
return deletedSampleUuids;
}
use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class UserRightsFacadeEjb method generateUserRightsDocument.
private void generateUserRightsDocument(Map<UserRole, Set<UserRight>> userRoleRights, OutputStream outStream) throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
// Create User Rights sheet
String safeName = WorkbookUtil.createSafeSheetName(I18nProperties.getCaption(Captions.userRights));
XSSFSheet sheet = workbook.createSheet(safeName);
// Define colors
final XSSFColor green = XssfHelper.createColor(0, 153, 0);
final XSSFColor red = XssfHelper.createColor(255, 0, 0);
final XSSFColor black = XssfHelper.createColor(0, 0, 0);
// Initialize cell styles
// Authorized style
XSSFCellStyle authorizedStyle = workbook.createCellStyle();
authorizedStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
authorizedStyle.setFillForegroundColor(green);
authorizedStyle.setBorderBottom(BorderStyle.THIN);
authorizedStyle.setBorderLeft(BorderStyle.THIN);
authorizedStyle.setBorderTop(BorderStyle.THIN);
authorizedStyle.setBorderRight(BorderStyle.THIN);
authorizedStyle.setBorderColor(BorderSide.BOTTOM, black);
authorizedStyle.setBorderColor(BorderSide.LEFT, black);
authorizedStyle.setBorderColor(BorderSide.TOP, black);
authorizedStyle.setBorderColor(BorderSide.RIGHT, black);
// Unauthorized style
XSSFCellStyle unauthorizedStyle = workbook.createCellStyle();
unauthorizedStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
unauthorizedStyle.setFillForegroundColor(red);
unauthorizedStyle.setBorderBottom(BorderStyle.THIN);
unauthorizedStyle.setBorderLeft(BorderStyle.THIN);
unauthorizedStyle.setBorderTop(BorderStyle.THIN);
unauthorizedStyle.setBorderRight(BorderStyle.THIN);
unauthorizedStyle.setBorderColor(BorderSide.BOTTOM, black);
unauthorizedStyle.setBorderColor(BorderSide.LEFT, black);
unauthorizedStyle.setBorderColor(BorderSide.TOP, black);
unauthorizedStyle.setBorderColor(BorderSide.RIGHT, black);
// Bold style
XSSFFont boldFont = workbook.createFont();
boldFont.setBold(true);
XSSFCellStyle boldStyle = workbook.createCellStyle();
boldStyle.setFont(boldFont);
int rowCounter = 0;
// Header
Row headerRow = sheet.createRow(rowCounter++);
Cell userRightHeadlineCell = headerRow.createCell(0);
userRightHeadlineCell.setCellValue(I18nProperties.getCaption(Captions.userRight));
userRightHeadlineCell.setCellStyle(boldStyle);
Cell descHeadlineCell = headerRow.createCell(1);
descHeadlineCell.setCellValue(I18nProperties.getCaption(Captions.UserRight_description));
descHeadlineCell.setCellStyle(boldStyle);
sheet.setColumnWidth(0, 256 * 35);
sheet.setColumnWidth(1, 256 * 50);
for (UserRole userRole : UserRole.values()) {
String columnCaption = userRole.toString();
Cell headerCell = headerRow.createCell(userRole.ordinal() + 2);
headerCell.setCellValue(columnCaption);
headerCell.setCellStyle(boldStyle);
sheet.setColumnWidth(userRole.ordinal() + 2, 256 * 14);
}
// Jurisdiction row (header)
final Row jurisdictionRow = sheet.createRow(rowCounter++);
final Cell jurisdictionHeadlineCell = jurisdictionRow.createCell(0);
jurisdictionHeadlineCell.setCellValue(I18nProperties.getCaption(Captions.UserRight_jurisdiction));
jurisdictionHeadlineCell.setCellStyle(boldStyle);
final Cell jurDescHeadlineCell = jurisdictionRow.createCell(1);
jurDescHeadlineCell.setCellValue(I18nProperties.getCaption(Captions.UserRight_jurisdictionOfRole));
jurDescHeadlineCell.setCellStyle(boldStyle);
for (UserRole userRole : UserRole.values()) {
final String columnCaption = userRole.getJurisdictionLevel().toString();
final Cell headerCell = jurisdictionRow.createCell(userRole.ordinal() + 2);
headerCell.setCellValue(columnCaption);
headerCell.setCellStyle(boldStyle);
}
// User right rows
for (UserRight userRight : UserRight.values()) {
Row row = sheet.createRow(rowCounter++);
// User right name
Cell nameCell = row.createCell(0);
nameCell.setCellValue(userRight.name());
nameCell.setCellStyle(boldStyle);
// User right description
Cell descCell = row.createCell(1);
descCell.setCellValue(userRight.toString());
// Add styled cells for all user roles
for (UserRole userRole : UserRole.values()) {
Cell roleRightCell = row.createCell(userRole.ordinal() + 2);
if (userRoleRights.containsKey(userRole) && userRoleRights.get(userRole).contains(userRight) || userRole.hasDefaultRight(userRight)) {
roleRightCell.setCellStyle(authorizedStyle);
roleRightCell.setCellValue(I18nProperties.getString(Strings.yes));
} else {
roleRightCell.setCellStyle(unauthorizedStyle);
roleRightCell.setCellValue(I18nProperties.getString(Strings.no));
}
}
}
XssfHelper.addAboutSheet(workbook);
workbook.write(outStream);
workbook.close();
}
use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class UserRoleConfigFacadeEjb method getEffectiveUserRights.
@Override
public Set<UserRight> getEffectiveUserRights(UserRole... userRoles) {
Map<UserRole, Set<UserRight>> userRoleRights = getUserRoleRightsCached();
Set<UserRight> userRights = EnumSet.noneOf(UserRight.class);
for (UserRole userRole : userRoles) {
userRights.addAll(userRoleRights.get(userRole));
}
return userRights;
}
use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class UserService method getAllByRegionsAndUserRoles.
/**
* @see #getReferenceList(List, List, List, boolean, boolean, boolean, List) This method is partly a duplication for getReferenceList,
* but it's still in use for WeeklyReports and messageRecipients where more information of the user is needed
* and method signatures rely on {@link User}.
*/
private List<User> getAllByRegionsAndUserRoles(List<Region> regions, Collection<UserRole> userRoles, BiFunction<CriteriaBuilder, Root<User>, Predicate> createExtraFilters) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<User> cq = cb.createQuery(getElementClass());
Root<User> from = cq.from(getElementClass());
Predicate filter = createDefaultFilter(cb, from);
if (regions != null) {
filter = from.get(User.REGION).in(regions);
}
if (!userRoles.isEmpty()) {
Join<User, UserRole> joinRoles = from.join(User.USER_ROLES, JoinType.LEFT);
Predicate rolesFilter = joinRoles.in(userRoles);
filter = CriteriaBuilderHelper.and(cb, filter, rolesFilter);
}
if (createExtraFilters != null) {
filter = CriteriaBuilderHelper.and(cb, filter, createExtraFilters.apply(cb, from));
}
if (filter != null) {
cq.where(filter);
}
cq.distinct(true).orderBy(cb.asc(from.get(AbstractDomainObject.ID)));
return em.createQuery(cq).getResultList();
}
use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class UserService method buildCriteriaFilter.
public Predicate buildCriteriaFilter(UserCriteria userCriteria, CriteriaBuilder cb, Root<User> from) {
Predicate filter = null;
if (userCriteria.getActive() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(User.ACTIVE), userCriteria.getActive()));
}
if (userCriteria.getUserRole() != null) {
Join<User, UserRole> joinRoles = from.join(User.USER_ROLES, JoinType.LEFT);
filter = CriteriaBuilderHelper.and(cb, filter, joinRoles.in(Collections.singletonList(userCriteria.getUserRole())));
}
if (userCriteria.getRegion() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.join(Case.REGION, JoinType.LEFT).get(AbstractDomainObject.UUID), userCriteria.getRegion().getUuid()));
}
if (userCriteria.getDistrict() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.join(Case.DISTRICT, JoinType.LEFT).get(AbstractDomainObject.UUID), userCriteria.getDistrict().getUuid()));
}
if (userCriteria.getFreeText() != null) {
String[] textFilters = userCriteria.getFreeText().split("\\s+");
for (String textFilter : textFilters) {
if (DataHelper.isNullOrEmpty(textFilter)) {
continue;
}
Predicate likeFilters = cb.or(CriteriaBuilderHelper.unaccentedIlike(cb, from.get(User.FIRST_NAME), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, from.get(User.LAST_NAME), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, from.get(User.USER_NAME), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, from.get(User.USER_EMAIL), textFilter), CriteriaBuilderHelper.ilike(cb, from.get(User.PHONE), textFilter), CriteriaBuilderHelper.ilike(cb, from.get(User.UUID), textFilter));
filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
}
return filter;
}
Aggregations