Skip to content

Commit

Permalink
Merge pull request #261 from ec-jrc/201-email-when-roles-changed
Browse files Browse the repository at this point in the history
201 email when roles changed
  • Loading branch information
oruscalleda authored Mar 20, 2023
2 parents aac76b5 + 1e6eeed commit 4e4a0d8
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import eu.europa.ec.re3gistry2.base.utility.Configuration;
import eu.europa.ec.re3gistry2.base.utility.BaseConstants;
import eu.europa.ec.re3gistry2.base.utility.InputSanitizerHelper;
import eu.europa.ec.re3gistry2.base.utility.MailManager;
import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory;
import eu.europa.ec.re3gistry2.base.utility.UserHelper;
import eu.europa.ec.re3gistry2.base.utility.WebConstants;
Expand Down Expand Up @@ -53,15 +54,19 @@
import eu.europa.ec.re3gistry2.model.RegRelationproposed;
import eu.europa.ec.re3gistry2.model.RegRole;
import eu.europa.ec.re3gistry2.model.RegUser;
import eu.europa.ec.re3gistry2.web.utility.SendEmailFromAction;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import javax.mail.internet.InternetAddress;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Persistence;
Expand Down Expand Up @@ -167,53 +172,53 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
// This is a view request


//Cache the parent of the proposed item
ItemCache cache = (ItemCache) request.getAttribute(BaseConstants.ATTRIBUTE_CACHE_KEY);
if (cache == null) {
cache = new EhCache();
request.setAttribute(BaseConstants.ATTRIBUTE_CACHE_KEY, cache);
}
if (formRegActionUuid != null){
RegAction regActionForCache;
List<RegItemproposed> regItemProposeds;
try{
regActionForCache = regActionManager.get(formRegActionUuid);
regItemProposeds = regItemproposedManager.getAll(regActionForCache);
}catch(Exception e){
regItemProposeds = Collections.emptyList();
}

HashSet<String> parentsList = new HashSet <String>();
HashSet<String> collectionsList = new HashSet <String>();
for (RegItemproposed regItemProposed : regItemProposeds) {
List<RegRelationproposed> collections = regRelationproposedManager.getAllByObject(regItemProposed);

if(collections != null && collections.size() > 0 ){
for (RegRelationproposed collection : collections) {
if(collection.getRegRelationpredicate().getLocalid().equals(BaseConstants.KEY_PREDICATE_COLLECTION)){
String uuid = collection.getRegItemObject().getUuid();
collectionsList.add(uuid);
}
}
}
if(regItemProposed.getRegAction() != null && regItemProposed.getRegAction().getRegItemRegister() != null){
if(regItemProposed.getRegAction().getRegItemRegister().getRegItemclass() != null && regItemProposed.getRegAction().getRegItemRegister().getRegItemclass().getUuid() != null){
String uuid = regItemProposed.getRegAction().getRegItemRegister().getRegItemclass().getUuid();
parentsList.add(uuid);
}
}
}
EntityManager emCache = PersistenceFactory.getEntityManagerFactory().createEntityManager();
CacheAll cacheAll = new CacheAll(emCache, cache, null);
for (String uuid : parentsList) {
// EntityManager emCache = Persistence.createEntityManagerFactory(BaseConstants.KEY_PROPERTY_PERSISTENCE_UNIT_NAME).createEntityManager();
cacheAll.run(uuid);
}
for (String uuid : collectionsList) {
// EntityManager emCache = Persistence.createEntityManagerFactory(BaseConstants.KEY_PROPERTY_PERSISTENCE_UNIT_NAME).createEntityManager();
cacheAll.run(uuid);
}
}
// //Cache the parent of the proposed item
// ItemCache cache = (ItemCache) request.getAttribute(BaseConstants.ATTRIBUTE_CACHE_KEY);
// if (cache == null) {
// cache = new EhCache();
// request.setAttribute(BaseConstants.ATTRIBUTE_CACHE_KEY, cache);
// }
// if (formRegActionUuid != null){
// RegAction regActionForCache;
// List<RegItemproposed> regItemProposeds;
// try{
// regActionForCache = regActionManager.get(formRegActionUuid);
// regItemProposeds = regItemproposedManager.getAll(regActionForCache);
// }catch(Exception e){
// regItemProposeds = Collections.emptyList();
// }
//
// HashSet<String> parentsList = new HashSet <String>();
// HashSet<String> collectionsList = new HashSet <String>();
// for (RegItemproposed regItemProposed : regItemProposeds) {
// List<RegRelationproposed> collections = regRelationproposedManager.getAllByObject(regItemProposed);
//
// if(collections != null && collections.size() > 0 ){
// for (RegRelationproposed collection : collections) {
// if(collection.getRegRelationpredicate().getLocalid().equals(BaseConstants.KEY_PREDICATE_COLLECTION)){
// String uuid = collection.getRegItemObject().getUuid();
// collectionsList.add(uuid);
// }
// }
// }
// if(regItemProposed.getRegAction() != null && regItemProposed.getRegAction().getRegItemRegister() != null){
// if(regItemProposed.getRegAction().getRegItemRegister().getRegItemclass() != null && regItemProposed.getRegAction().getRegItemRegister().getRegItemclass().getUuid() != null){
// String uuid = regItemProposed.getRegAction().getRegItemRegister().getRegItemclass().getUuid();
// parentsList.add(uuid);
// }
// }
// }
// EntityManager emCache = PersistenceFactory.getEntityManagerFactory().createEntityManager();
// CacheAll cacheAll = new CacheAll(emCache, cache, null);
// for (String uuid : parentsList) {
//// EntityManager emCache = Persistence.createEntityManagerFactory(BaseConstants.KEY_PROPERTY_PERSISTENCE_UNIT_NAME).createEntityManager();
// cacheAll.run(uuid);
// }
// for (String uuid : collectionsList) {
//// EntityManager emCache = Persistence.createEntityManagerFactory(BaseConstants.KEY_PROPERTY_PERSISTENCE_UNIT_NAME).createEntityManager();
// cacheAll.run(uuid);
// }
// }


// Getting the submitting organization RegRole
Expand Down Expand Up @@ -269,13 +274,22 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
} catch (NoResultException e) {
}
}



if (regItemproposeds == null && regAction!=null) {
regItemproposeds = (List<RegItemproposed>) regItemproposedManager.getAll(regAction);
}

request.setAttribute(BaseConstants.KEY_REQUEST_ACTION_LIST, regActions);
request.setAttribute(BaseConstants.KEY_REQUEST_ACTION, regAction);
request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_PROPOSEDS, regItemproposeds);
request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_HISTORYS, regItemhistorys);
request.setAttribute(BaseConstants.KEY_REQUEST_REGITEMS, regItems);


if (formRegActionUuid != null && formRegActionUuid.length() > 0 && formSubmitAction != null && formSubmitAction.length() > 0 && formActionType != null && formActionType.length() > 0) {
MailManager.sendActionMail(regItemproposeds, regAction, Configuration.getInstance().getLocalization(), BaseConstants.KEY_FIELD_MANDATORY_CONTROLBODY);
}

//Dispatch request
request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_CONTROLBODY + WebConstants.PAGE_URINAME_CONTROLBODY + WebConstants.PAGE_JSP_EXTENSION).forward(request, response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import eu.europa.ec.re3gistry2.base.utility.BaseConstants;
import eu.europa.ec.re3gistry2.base.utility.Configuration;
import eu.europa.ec.re3gistry2.base.utility.InputSanitizerHelper;
import eu.europa.ec.re3gistry2.base.utility.MailManager;
import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory;
import eu.europa.ec.re3gistry2.javaapi.handler.RegItemproposedHandler;
import eu.europa.ec.re3gistry2.model.RegUser;
Expand Down Expand Up @@ -120,6 +121,8 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp

// get all regItemProposed for this action
List<RegItemproposed> regItemproposedList = regItemproposedManager.getAll(regAction);

MailManager.sendActionMail(regItemproposedList, regAction, Configuration.getInstance().getLocalization(), BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS);

if (!regItemproposedList.isEmpty()) {
for (RegItemproposed regItemproposed : regItemproposedList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import eu.europa.ec.re3gistry2.base.utility.Configuration;
import eu.europa.ec.re3gistry2.base.utility.BaseConstants;
import eu.europa.ec.re3gistry2.base.utility.InputSanitizerHelper;
import eu.europa.ec.re3gistry2.base.utility.MailManager;
import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory;
import eu.europa.ec.re3gistry2.base.utility.UserHelper;
import eu.europa.ec.re3gistry2.base.utility.WebConstants;
Expand All @@ -48,6 +49,7 @@
import eu.europa.ec.re3gistry2.model.RegRole;
import eu.europa.ec.re3gistry2.model.RegUser;
import eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping;
import eu.europa.ec.re3gistry2.web.utility.SendEmailFromAction;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
Expand All @@ -56,6 +58,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
Expand Down Expand Up @@ -276,7 +279,11 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_PROPOSEDS, regItemproposeds);
request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_HISTORYS, regItemhistorys);
request.setAttribute(BaseConstants.KEY_REQUEST_REGITEMS, regItems);


if (formRegActionUuid != null && formRegActionUuid.length() > 0 && formSubmitAction != null && formSubmitAction.length() > 0) {
MailManager.sendActionMail(regItemproposeds, regAction, Configuration.getInstance().getLocalization(), BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS);
}

//Dispatch request
request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_SUBMITTINGORGANISATIONS + WebConstants.PAGE_URINAME_SUBMITTINGORGANISATIONS + WebConstants.PAGE_JSP_EXTENSION).forward(request, response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ application.language.label.en=English (en)
#application.language.label.it=Italiano (it)
application.language.defaultLocale=en

application.default.name = Re3gistry2

# ECAS base URL (authetication method)
application.ecas.baseurl = https://webgate.ec.europa.eu

Expand Down Expand Up @@ -177,6 +179,15 @@ mail.text.body.groupschanged.ending=<br/><br/> Access your user profile page det
mail.text.body.groupschanged.ending.contact=Registry software
mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry

mail.text.body.itemaction.basebody=The following item(s) were changed: <br/>
mail.text.body.itemaction.acceptedwithchanges=accepted with changes
mail.text.body.itemaction.notaccepted=not accepted
mail.text.body.itemaction.rejected=rejected
mail.text.body.itemaction.basebody.controlbody=Actions on the Control Body were made
mail.text.body.itemaction.basebody.submitting=Actions on the Submitting Organizations were made
mail.text.body.itemaction.proposedby= proposed by
mail.text.body.itemaction.was= was
mail.text.body.itemaction.actionmadeby=. The action was made by

### Webapp properties ####
web.application_root_url=${application.rooturl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ role.permissions.registerOwner=ManageUser,ManageGroup,MapUserToGroup
role.permissions.controlBody=ApproveProposal
role.permissions.submittingOrganization=ManageItemProposal,SubmitProposal

application.default.name

#### End Roles and permissions section #########################################

### Mail ###
Expand Down Expand Up @@ -172,6 +174,16 @@ mail.text.body.groupschanged.ending=<br/><br/> Access your user profile page det
mail.text.body.groupschanged.ending.contact=Registry software
mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry

mail.text.body.itemaction.basebody=The following item(s) were changed: <br/>
mail.text.body.itemaction.acceptedwithchanges=accepted with changes
mail.text.body.itemaction.notaccepted=not accepted
mail.text.body.itemaction.rejected=rejected
mail.text.body.itemaction.basebody.controlbody=Actions on the Control Body were made
mail.text.body.itemaction.basebody.submitting=Actions on the Submitting Organizations were made
mail.text.body.itemaction.proposedby= proposed by
mail.text.body.itemaction.was= was
mail.text.body.itemaction.actionmadeby=. The action was made by

mail.text.subject.bulkimport.success=Re3gistry - bulk import {itemclass} success
mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error
mail.text.body.bulkimport.success=Dear {name}, <br/><br/> The bulk import has been completed with success.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ discard.contentclass.confirm=Are you sure you want to remove the content class?

profile.label.title = User profile

application.default.name = Re3gistry2

#installation fileds

installation.main.title=Re3gistry installation wizard
Expand Down Expand Up @@ -622,6 +624,16 @@ mail.text.body.groupschanged.ending=<br/><br/> Access your user profile page det
mail.text.body.groupschanged.ending.contact=Registry software
mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry

mail.text.body.itemaction.basebody=The following item(s) were changed: <br/>
mail.text.body.itemaction.acceptedwithchanges=accepted with changes
mail.text.body.itemaction.notaccepted=not accepted
mail.text.body.itemaction.rejected=rejected
mail.text.body.itemaction.basebody.controlbody=Actions on the Control Body were made
mail.text.body.itemaction.basebody.submitting=Actions on the Submitting Organizations were made
mail.text.body.itemaction.proposedby= proposed by
mail.text.body.itemaction.was= was
mail.text.body.itemaction.actionmadeby=. The action was made by

#tooltiop add registry
registry.tooltip=Target registry where the register that you are about to create will be sitting
registry.path.tooltip=This option allows to include the 'registry' word for all the elements belonging to the register that you are about to create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class BaseConstants {
public static final String KEY_PROPERTY_LOGIN_TYPE = "application.login.type";
public static final String KEY_PROPERTY_LOGIN_TYPE_SHIRO = "SHIRO";
public static final String KEY_PROPERTY_LOGIN_TYPE_ECAS = "ECAS";

public static final String KEY_PROPERTY_APP_DEFAULT_NAME = "application.default.name";

public static final String KEY_PROPERTY_INTERFACE_TYPE = "application.selected.interface";
public static final String KEY_PROPERTY_INTERFACE_NEUTRAL_TYPE = "neutral";
Expand Down Expand Up @@ -151,7 +153,17 @@ public class BaseConstants {
public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING = "mail.text.body.groupschanged.ending";
public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_NAME = "mail.text.body.groupschanged.ending.contact";
public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_WEBPAGE = "mail.text.body.groupschanged.ending.contact.webpage";


public static final String KEY_EMAIL_SUBJECT_ITEMACTION_CONTROLBODY = "mail.text.body.itemaction.basebody.controlbody";
public static final String KEY_EMAIL_SUBJECT_ITEMACTION_SUBMITTINGORG = "mail.text.body.itemaction.basebody.submitting";
public static final String KEY_EMAIL_BODY_ITEMACTION_BASE = "mail.text.body.itemaction.basebody";
public static final String KEY_EMAIL_BODY_ITEMACTION_ACCEPTEDWCHANGES = "mail.text.body.itemaction.acceptedwithchanges";
public static final String KEY_EMAIL_BODY_ITEMACTION_NOTACCEPTED = "mail.text.body.itemaction.notaccepted";
public static final String KEY_EMAIL_BODY_ITEMACTION_REJECTED = "mail.text.body.itemaction.rejected";
public static final String KEY_EMAIL_BODY_ITEMACTION_PROPOSEDBY = "mail.text.body.itemaction.proposedby";
public static final String KEY_EMAIL_BODY_ITEMACTION_WAS = "mail.text.body.itemaction.was";
public static final String KEY_EMAIL_BODY_ITEMACTION_ACTIONMADEBY = "mail.text.body.itemaction.actionmadeby";

/**
* mail subject and body bulk import
*/
Expand Down
Loading

0 comments on commit 4e4a0d8

Please sign in to comment.