Skip to content

Commit

Permalink
[KNOWAGE-8123] Cannot delete just created role
Browse files Browse the repository at this point in the history
  • Loading branch information
masseb974 committed Oct 31, 2024
1 parent 11f26f5 commit c6c666b
Show file tree
Hide file tree
Showing 28 changed files with 251 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ public Response getRoleById(@PathParam("id") Integer id) {
}
}

@GET
@UserConstraint(functionalities = { CommunityFunctionalityConstants.PROFILE_MANAGEMENT })
@Path("/{id}/allElement")
@Produces(MediaType.APPLICATION_JSON + CHARSET)
public Response getRoleAllElemntById(@PathParam("id") Integer id) {
IRoleDAO rolesDao = null;

try {
Role role = null;
rolesDao = DAOFactory.getRoleDAO();
rolesDao.setUserProfile(getUserProfile());
role = rolesDao.loadAllElemtnsForRoleByID(id);
return Response.ok(role).build();
} catch (Exception e) {
LOGGER.error("Role with selected id: " + id + " doesn't exists", e);
throw new SpagoBIRestServiceException("Item with selected id: " + id + " doesn't exists",
buildLocaleFromSession(), e);
}
}

@GET
@Produces(MediaType.APPLICATION_JSON + CHARSET)
@Path("/idsByNames")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public class EventsManager {
* @return single instance of EventsManager
*/
public static EventsManager getInstance() {
if (instance == null)
if (instance == null) {
instance = new EventsManager();
}
return instance;
}

Expand Down Expand Up @@ -102,7 +103,6 @@ public Integer registerEvent(String user, String desc, String params, List roles
eventLog.setDate(new Timestamp(System.currentTimeMillis()));
eventLog.setParams(params);
eventLog.setType(type);
eventLog.setRoles(roles);
try {
EventLogDAOHibImpl eventLogDAO = new EventLogDAOHibImpl();
eventLogDAO.setUserID(user);
Expand Down Expand Up @@ -145,16 +145,17 @@ public EventLog getRegisteredEvent(Integer id) {
*/
public static String getParamsStr(Map params) {
logger.debug("IN");
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
Iterator it = params.keySet().iterator();
boolean isFirstParameter = true;
while (it.hasNext()) {
String pname = (String) it.next();
String pvalue = (String) params.get(pname);
if (!isFirstParameter)
if (!isFirstParameter) {
buffer.append("&");
else
} else {
isFirstParameter = false;
}
buffer.append(pname + "=" + pvalue);
}
logger.debug("OUT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public interface IRoleDAO extends ISpagoBIDao, EmittingEventDAO<RoleEventsEmitti
*/
Role loadByID(Integer roleID) throws EMFUserError;

Role loadAllElemtnsForRoleByID(Integer roleID) throws EMFUserError;

SbiExtRoles loadSbiExtRoleById(Integer roleId) throws EMFUserError;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
Expand All @@ -44,6 +45,7 @@

import it.eng.spago.error.EMFErrorSeverity;
import it.eng.spago.error.EMFUserError;
import it.eng.spagobi.analiticalmodel.functionalitytree.metadata.SbiFuncRole;
import it.eng.spagobi.behaviouralmodel.analyticaldriver.metadata.SbiParuse;
import it.eng.spagobi.behaviouralmodel.analyticaldriver.metadata.SbiParuseDet;
import it.eng.spagobi.commons.bo.Role;
Expand All @@ -59,7 +61,10 @@
import it.eng.spagobi.commons.metadata.SbiOrganizationProductType;
import it.eng.spagobi.commons.metadata.SbiProductType;
import it.eng.spagobi.mapcatalogue.metadata.SbiGeoLayersRoles;
import it.eng.spagobi.profiling.bean.SbiUser;
import it.eng.spagobi.tools.news.metadata.SbiNews;
import it.eng.spagobi.utilities.exceptions.SpagoBIRuntimeException;
import it.eng.spagobi.wapp.metadata.SbiMenu;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
Expand Down Expand Up @@ -117,6 +122,72 @@ public Role loadByID(Integer roleID) throws EMFUserError {
return toReturn;
}

@Override
public Role loadAllElemtnsForRoleByID(Integer roleID) throws EMFUserError {
Monitor m = MonitorFactory.start("knowage_loadAllElemtnByID");
Role toReturn = null;
Session aSession = null;
Transaction tx = null;

try {
aSession = getSession();
tx = aSession.beginTransaction();

SbiExtRoles hibRole = (SbiExtRoles) aSession.load(SbiExtRoles.class, roleID);
toReturn = toRole(hibRole);

if (hibRole.getSbiFuncRoles() != null && !hibRole.getSbiFuncRoles().isEmpty()) {
toReturn.setRoleFunzionalities((List<String>) hibRole.getSbiFuncRoles().stream().map(x -> ((SbiFuncRole) x).getId().getFunction().getPath())
.distinct().collect(Collectors.toList()));
}

if (hibRole.getSbiParuseDets() != null && !hibRole.getSbiParuseDets().isEmpty()) {

toReturn.setRoleAnaliticalDrivers((List<String>) hibRole.getSbiParuseDets().stream()
.map(x -> ((SbiParuseDet) x).getId().getSbiParuse().getSbiParameters().getLabel()).distinct().collect(Collectors.toList()));

}

if (hibRole.getSbiNewsRoles() != null && !hibRole.getSbiNewsRoles().isEmpty()) {

toReturn.setRoleNews(
(List<String>) hibRole.getSbiNewsRoles().stream().map(x -> ((SbiNews) x).getName()).distinct().collect(Collectors.toList()));

}

if (hibRole.getSbiLayersRoles() != null && !hibRole.getSbiLayersRoles().isEmpty()) {

toReturn.setRoleLayers(
hibRole.getSbiLayersRoles().stream().map(x -> x.getName()).distinct().toList());

}

if (hibRole.getSbiUsersRoles() != null && !hibRole.getSbiUsersRoles().isEmpty()) {

toReturn.setRoleUsers(hibRole.getSbiUsersRoles().stream().map(SbiUser::getUserId).distinct().toList());

}

if (hibRole.getSbiMenuRoles() != null && !hibRole.getSbiMenuRoles().isEmpty()) {

toReturn.setRoleMenu(hibRole.getSbiMenuRoles().stream().map(SbiMenu::getName).distinct().toList());

}


tx.commit();
} catch (HibernateException he) {
logException(he);
rollbackIfActive(tx);
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
closeSessionIfOpen(aSession);
}

m.stop();
return toReturn;
}

@Override
public SbiExtRoles loadSbiExtRoleById(Integer roleId) throws EMFUserError {
SbiExtRoles toReturn = null;
Expand Down Expand Up @@ -160,8 +231,9 @@ public Role loadByName(String roleName) throws EMFUserError {
tx = aSession.beginTransaction();

SbiExtRoles hibRole = loadByNameInSession(roleName, aSession);
if (hibRole == null)
if (hibRole == null) {
return null;
}

toReturn = toRole(hibRole);
putIntoCache(roleName, toReturn);
Expand Down Expand Up @@ -506,7 +578,7 @@ public void modifyRole(Role aRole) throws EMFUserError {

SbiAuthorizationsRoles fr = new SbiAuthorizationsRoles();
SbiAuthorizationsRolesId id = new SbiAuthorizationsRolesId(authI.getId(), hibRole.getExtRoleId());


fr.setSbiExtRoles(hibRole);
fr.setSbiAuthorizations(authI);
Expand Down Expand Up @@ -585,7 +657,7 @@ private boolean isAbleTo(Role aRole, SbiAuthorizations authI) {
|| (authI.getName().equals("ENABLE_DOSSIER") && aRole.getAbleToUseDossier())
|| (authI.getName().equals("ENABLE_DASHBOARD_THEME_MANAGEMENT") && aRole.getAbleToUseDashboardThemeManagement());


}

/**
Expand Down Expand Up @@ -894,7 +966,7 @@ public Role toRole(SbiExtRoles hibRole) {
if(name.equals("ENABLE_DASHBOARD_THEME_MANAGEMENT")){
role.setAbleToUseDashboardThemeManagement(true);
}


}

Expand Down Expand Up @@ -1124,8 +1196,9 @@ public List<Role> loadPagedRolesList(Integer offset, Integer fetchSize) throws E
hibernateQuery = aSession.createQuery("from SbiExtRoles order by name");

hibernateQuery.setFirstResult(offset);
if (fetchSize > 0)
if (fetchSize > 0) {
hibernateQuery.setMaxResults(fetchSize);
}

toTransform = hibernateQuery.list();

Expand Down Expand Up @@ -1740,8 +1813,9 @@ public Role loadPublicRole() throws EMFUserError {

Object hibRoleO = query.uniqueResult();

if (hibRoleO == null)
if (hibRoleO == null) {
return null;
}

SbiExtRoles hibRole = (SbiExtRoles) hibRoleO;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.util.Set;

import it.eng.spagobi.commons.dao.dto.SbiCategory;
import it.eng.spagobi.mapcatalogue.metadata.SbiGeoLayers;
import it.eng.spagobi.profiling.bean.SbiUser;
import it.eng.spagobi.wapp.metadata.SbiMenu;

/**
* SbiExtRoles generated by hbm2java
Expand All @@ -44,6 +47,9 @@ public class SbiExtRoles extends SbiHibernateModel {
private Set sbiDataSetCategories;
private Set sbiAuthorizationsRoleses = new HashSet();
private Set sbiNewsRoles = new HashSet();
private Set<SbiGeoLayers> sbiLayersRoles = new HashSet();
private Set<SbiUser> sbiUsersRoles = new HashSet();
private Set<SbiMenu> sbiMenuRoles = new HashSet();

// Constructors

Expand Down Expand Up @@ -260,6 +266,30 @@ public void setSbiNewsRoles(Set sbiNewsRoles) {
this.sbiNewsRoles = sbiNewsRoles;
}

public Set<SbiGeoLayers> getSbiLayersRoles() {
return sbiLayersRoles;
}

public void setSbiLayersRoles(Set<SbiGeoLayers> sbiLayersRoles) {
this.sbiLayersRoles = sbiLayersRoles;
}

public Set<SbiUser> getSbiUsersRoles() {
return sbiUsersRoles;
}

public void setSbiUsersRoles(Set<SbiUser> sbiUsersRoles) {
this.sbiUsersRoles = sbiUsersRoles;
}

public Set<SbiMenu> getSbiMenuRoles() {
return sbiMenuRoles;
}

public void setSbiMenuRoles(Set<SbiMenu> sbiMenuRoles) {
this.sbiMenuRoles = sbiMenuRoles;
}

/*
* (non-Javadoc)
*
Expand All @@ -280,24 +310,29 @@ public int hashCode() {
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
SbiExtRoles other = (SbiExtRoles) obj;
if (extRoleId == null) {
if (other.extRoleId != null)
if (other.extRoleId != null) {
return false;
} else if (!extRoleId.equals(other.extRoleId))
}
} else if (!extRoleId.equals(other.extRoleId)) {
return false;
}
return true;
}

public void changeExtRoleId(Integer id) {
this.setExtRoleId(id);

}

}
23 changes: 2 additions & 21 deletions knowagedao/src/main/java/it/eng/spagobi/events/bo/EventLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class EventLog implements Serializable {
private String desc;
private String params;
private EventType type;
private List roles;

private static Logger logger = Logger.getLogger(EventLog.class);

Expand Down Expand Up @@ -152,25 +151,6 @@ public void setUser(String user) {
this.user = user;
}

/**
* Gets the roles.
*
* @return the roles
*/
public List getRoles() {
return roles;
}

/**
* Sets the roles.
*
* @param roles
* the new roles
*/
public void setRoles(List roles) {
this.roles = roles;
}

/**
* Gets the type.
*
Expand All @@ -195,8 +175,9 @@ public String getFormattedDescription() {
if (description != null) {
description = GeneralUtilities.replaceInternationalizedMessages(description);
description = description.replaceAll("<br/>", " ");
if (description.length() > 50)
if (description.length() > 50) {
description = description.substring(0, 50) + "...";
}
description = description.replaceAll(">", "&gt;");
description = description.replaceAll("<", "&lt;");
description = description.replaceAll("\"", "&quot;");
Expand Down
Loading

0 comments on commit c6c666b

Please sign in to comment.