Skip to content

Commit

Permalink
Added control on the reopening of the application which can only be c…
Browse files Browse the repository at this point in the history
…arried out by the users present in the group configured in the call
  • Loading branch information
mspasiano committed Mar 19, 2024
1 parent 1e749c1 commit ff3a485
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ public Response pasteApplication(@Context HttpServletRequest request,
@Path("reopen")
public Response reopenApplication(@Context HttpServletRequest request,
@FormParam("cmis:objectId") String applicationSourceId) {
String userId = getUserId(request);
ResponseBuilder rb;
applicationService.reopenApplication(cmisService.getCurrentCMISSession(request),
try {
String userId = getUserId(request);
applicationService.reopenApplication(cmisService.getCurrentCMISSession(request),
applicationSourceId, Utility.getContextURL(request), request.getLocale(), userId);
return Response.ok().build();
return Response.ok().build();
} catch (ClientMessageException e) {
LOGGER.warn("Send application error: {}", e.getMessage());
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(Collections.singletonMap("message", e.getMessage())).build();
}
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,14 @@ public void reopenApplication(Session currentCMISSession, final String applicati
!newApplication.getPropertyValue(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value()).equals(StatoDomanda.CONFERMATA.getValue())) {
throw new ClientMessageException("message.error.domanda.no.confermata");
}
CMISUser loginUser = userService.loadUserForConfirm(userId);
try {
callService.isBandoInCorso(call,
userService.loadUserForConfirm(userId));
callService.isBandoInCorso(call,loginUser);
} catch (CoolUserFactoryException e) {
throw new CMISApplicationException("Error loading user: " + userId, e);
}
groupCanSubmitApplication(call, loginUser, locale);

String link = cmisService.getBaseURL().concat("service/cnr/jconon/manage-application/reopen");
UrlBuilder url = new UrlBuilder(link);
Response resp = cmisService.getHttpInvoker(cmisService.getAdminSession()).invokePOST(url, MimeTypes.JSON.mimetype(),
Expand Down Expand Up @@ -1247,28 +1249,7 @@ else if (!application.getParentId().equals(call.getId()))
throw new ClientMessageException(
i18nService.getLabel("message.error.bando.cannot.submit.application.spid", locale));
}

/**
* Se nel bando è valorizzato il gruppo delle utenze viene controllata la presenza
* dell'utenza specifica nel gruppo
*/
final Optional<String> groupCanSubmitApplication =
Optional.ofNullable(call.<String>getPropertyValue(JCONONPropertyIds.CALL_GROUP_CAN_SUBMIT_APPLICATION.value()));
if (groupCanSubmitApplication
.map(groupName -> !loginUser.getGroupsArray().contains(groupName))
.orElse(Boolean.FALSE)) {
throw new ClientMessageException(
i18nService.getLabel("message.error.bando.cannot.submit.application",
locale,
groupService.loadGroup(
groupCanSubmitApplication
.map(s -> s.replaceAll("GROUP_", ""))
.orElseThrow(() -> new CMISApplicationException("Cannot find GROUP")),
cmisService.getAdminSession()
).getDisplay_name())
);
}

groupCanSubmitApplication(call, loginUser, locale);
// In un bando di mobilità può accedere solo un non dipendente
// Se application è vuoto vuol dire che si sta creando la domanda e
// quindi l'utente collegato non deve essere un dipendente
Expand Down Expand Up @@ -1318,6 +1299,30 @@ else if (isDomandaInviata(application, loginUser)) {
return application;
}

private void groupCanSubmitApplication(Folder call, CMISUser loginUser, Locale locale) {
/**
* Se nel bando è valorizzato il gruppo delle utenze viene controllata la presenza
* dell'utenza specifica nel gruppo
*/
final Optional<String> groupCanSubmitApplication =
Optional.ofNullable(call.<String>getPropertyValue(JCONONPropertyIds.CALL_GROUP_CAN_SUBMIT_APPLICATION.value()));
if (groupCanSubmitApplication
.map(groupName -> !loginUser.getGroupsArray().contains(groupName))
.orElse(Boolean.FALSE)) {
throw new ClientMessageException(
i18nService.getLabel("message.error.bando.cannot.submit.application",
locale,
groupService.loadGroup(
groupCanSubmitApplication
.map(s -> s.replaceAll("GROUP_", ""))
.orElseThrow(() -> new CMISApplicationException("Cannot find GROUP")),
cmisService.getAdminSession()
).getDisplay_name())
);
}

}

protected boolean isDomandaInviata(Folder application, CMISUser loginUser) {
return application.getPropertyValue(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value()).equals(StatoDomanda.CONFERMATA.getValue()) &&
application.getPropertyValue(JCONONPropertyIds.APPLICATION_DATA_DOMANDA.value()) != null && !loginUser.isAdmin();
Expand Down

0 comments on commit ff3a485

Please sign in to comment.