Skip to content

Commit

Permalink
Merge pull request #394 from hashmapinc/tempus-190-user-dashboard
Browse files Browse the repository at this point in the history
Tempus 190 user dashboard
  • Loading branch information
cherrera2001 authored Jun 1, 2018
2 parents 026e0b5 + bfd2b5a commit 32ccd1d
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public Application saveApplication(@RequestBody Application application) throws
Application savedApplication = checkNotNull(applicationService.saveApplication(application));

logEntityAction(savedApplication.getId(), savedApplication,
savedApplication.getCustomerId(),
application.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
savedApplication.getCustomerId(),
application.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);

return savedApplication;
} catch (Exception e) {

logEntityAction(emptyId(EntityType.APPLICATION), application,
null,
application.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
null,
application.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);

throw handleException(e);
}
Expand Down Expand Up @@ -94,14 +94,14 @@ public void deleteApplication(@PathVariable("applicationId") String strApplicati
cleanupApplicationRelatedEntities(application);

logEntityAction(application.getId(),application, application.getCustomerId(),
ActionType.DELETED, null, strApplicationId );
ActionType.DELETED, null, strApplicationId );

} catch (Exception e) {

logEntityAction(emptyId(EntityType.APPLICATION),
null ,
null,
ActionType.DELETED, e, strApplicationId );
null ,
null,
ActionType.DELETED, e, strApplicationId );

throw handleException(e);
}
Expand Down Expand Up @@ -172,7 +172,7 @@ public Set<String> findApplicationsByruleIds(@PathVariable String[] strRuleIds)
return applicationService.findApplicationByRuleIds(tenantId, ruleIds);
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/applications/dashboard/{dashboardId}", method = RequestMethod.GET)
@ResponseBody
public List<String> findApplicationsByDashboardId(@PathVariable("dashboardId") String strDashboardId) throws TempusException {
Expand Down Expand Up @@ -355,15 +355,15 @@ public void activateApplicationById(@PathVariable("applicationId") String strApp
activateApplication(application);

logEntityAction(application.getId(),application,
application.getCustomerId(),
ActionType.ACTIVATED, null, strApplicationId);
application.getCustomerId(),
ActionType.ACTIVATED, null, strApplicationId);

} catch (Exception e) {

logEntityAction(emptyId(EntityType.APPLICATION),
null,
null,
ActionType.ACTIVATED,e , strApplicationId);
null,
null,
ActionType.ACTIVATED,e , strApplicationId);

throw handleException(e);
}
Expand Down Expand Up @@ -427,15 +427,15 @@ public void suspendApplicationById(@PathVariable("applicationId") String strAppl
applicationService.suspendApplicationById(applicationId);

logEntityAction(application.getId(),application,
application.getCustomerId(),
ActionType.SUSPENDED, null, strApplicationId);
application.getCustomerId(),
ActionType.SUSPENDED, null, strApplicationId);

} catch (Exception e) {

logEntityAction(emptyId(EntityType.APPLICATION),
null,
null,
ActionType.SUSPENDED,e , strApplicationId);
null,
null,
ActionType.SUSPENDED,e , strApplicationId);

throw handleException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.hashmapinc.server.common.data.page.TextPageLink;
import com.hashmapinc.server.common.data.page.TimePageLink;
import com.hashmapinc.server.common.data.plugin.ComponentLifecycleEvent;
import com.hashmapinc.server.common.data.security.Authority;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -73,28 +74,41 @@ public Dashboard getDashboardById(@PathVariable(DASHBOARD_ID) String strDashboar
}
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN' , 'CUSTOMER_USER')")
@RequestMapping(value = "/dashboard", method = RequestMethod.POST)
@ResponseBody
@ResponseBody
public Dashboard saveDashboard(@RequestBody Dashboard dashboard) throws TempusException {
try {
dashboard.setTenantId(getCurrentUser().getTenantId());
User user = getCurrentUser();
dashboard.setTenantId(user.getTenantId());

Dashboard savedDashboard = checkNotNull(dashboardService.saveDashboard(dashboard));

if((user).getAuthority().compareTo(Authority.CUSTOMER_USER) == 0) {
savedDashboard = autoAssignedUserToDashboard(savedDashboard.getId(),user.getCustomerId());
}

logEntityAction(savedDashboard.getId(), savedDashboard,
null,
dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
null,
dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);

return savedDashboard;
} catch (Exception e) {
logEntityAction(emptyId(EntityType.DASHBOARD), dashboard,
null, dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e);
null, dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e);

throw handleException(e);
}
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
private Dashboard autoAssignedUserToDashboard(DashboardId dashboardId,CustomerId customerId)throws TempusException {
Dashboard savedDashboard;
savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, customerId));
return savedDashboard;
}


@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/dashboard/{dashboardId}", method = RequestMethod.DELETE)
@ResponseStatus(value = HttpStatus.OK)
public void deleteDashboard(@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException {
Expand All @@ -106,25 +120,25 @@ public void deleteDashboard(@PathVariable(DASHBOARD_ID) String strDashboardId) t
actorService.onDashboardStateChange(getTenantId(), dashboardId, ComponentLifecycleEvent.DELETED);

logEntityAction(dashboardId, dashboard,
null,
ActionType.DELETED, null, strDashboardId);
null,
ActionType.DELETED, null, strDashboardId);

} catch (Exception e) {

logEntityAction(emptyId(EntityType.DASHBOARD),
null,
null,
ActionType.DELETED, e, strDashboardId);
null,
null,
ActionType.DELETED, e, strDashboardId);

throw handleException(e);
}
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/{customerId}/dashboard/{dashboardId}", method = RequestMethod.POST)
@ResponseBody
@ResponseBody
public Dashboard assignDashboardToCustomer(@PathVariable("customerId") String strCustomerId,
@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException {
@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException {
checkParameter("customerId", strCustomerId);
checkParameter(DASHBOARD_ID, strDashboardId);
try {
Expand All @@ -133,28 +147,28 @@ public Dashboard assignDashboardToCustomer(@PathVariable("customerId") String st

DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
checkDashboardId(dashboardId);

Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, customerId));

logEntityAction(dashboardId, savedDashboard,
customerId,
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, strCustomerId, customer.getName());
customerId,
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, strCustomerId, customer.getName());


return savedDashboard;
} catch (Exception e) {

logEntityAction(emptyId(EntityType.DASHBOARD), null,
null,
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId, strCustomerId);
null,
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId, strCustomerId);

throw handleException(e);
}
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/dashboard/{dashboardId}", method = RequestMethod.DELETE)
@ResponseBody
@ResponseBody
public Dashboard unassignDashboardFromCustomer(@PathVariable("customerId") String strCustomerId,
@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException {
checkParameter("customerId", strCustomerId);
Expand All @@ -168,21 +182,21 @@ public Dashboard unassignDashboardFromCustomer(@PathVariable("customerId") Strin
Dashboard savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(dashboardId, customerId));

logEntityAction(dashboardId, dashboard,
customerId,
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customer.getId().toString(), customer.getName());
customerId,
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customer.getId().toString(), customer.getName());

return savedDashboard;
} catch (Exception e) {

logEntityAction(emptyId(EntityType.DASHBOARD), null,
null,
ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);
null,
ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);

throw handleException(e);
}
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/dashboard/{dashboardId}/customers", method = RequestMethod.POST)
@ResponseBody
public Dashboard updateDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDashboardId,
Expand Down Expand Up @@ -224,24 +238,24 @@ public Dashboard updateDashboardCustomers(@PathVariable(DASHBOARD_ID) String str
savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, customerId));
ShortCustomerInfo customerInfo = savedDashboard.getAssignedCustomerInfo(customerId);
logEntityAction(dashboardId, savedDashboard,
customerId,
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
customerId,
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
}
for (CustomerId customerId : removedCustomerIds) {
ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId);
savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(dashboardId, customerId));
logEntityAction(dashboardId, dashboard,
customerId,
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
customerId,
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());

}
return savedDashboard;
}
} catch (Exception e) {

logEntityAction(emptyId(EntityType.DASHBOARD), null,
null,
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);
null,
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);

throw handleException(e);
}
Expand Down Expand Up @@ -275,22 +289,22 @@ public Dashboard addDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDas
savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, customerId));
ShortCustomerInfo customerInfo = savedDashboard.getAssignedCustomerInfo(customerId);
logEntityAction(dashboardId, savedDashboard,
customerId,
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
customerId,
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
}
return savedDashboard;
}
} catch (Exception e) {

logEntityAction(emptyId(EntityType.DASHBOARD), null,
null,
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);
null,
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);

throw handleException(e);
}
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/dashboard/{dashboardId}/customers/remove", method = RequestMethod.POST)
@ResponseBody
public Dashboard removeDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDashboardId,
Expand Down Expand Up @@ -318,17 +332,17 @@ public Dashboard removeDashboardCustomers(@PathVariable(DASHBOARD_ID) String str
ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId);
savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(dashboardId, customerId));
logEntityAction(dashboardId, dashboard,
customerId,
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
customerId,
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());

}
return savedDashboard;
}
} catch (Exception e) {

logEntityAction(emptyId(EntityType.DASHBOARD), null,
null,
ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);
null,
ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);

throw handleException(e);
}
Expand All @@ -346,15 +360,15 @@ public Dashboard assignDashboardToPublicCustomer(@PathVariable(DASHBOARD_ID) Str
Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, publicCustomer.getId()));

logEntityAction(dashboardId, savedDashboard,
publicCustomer.getId(),
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, publicCustomer.getId().toString(), publicCustomer.getName());
publicCustomer.getId(),
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, publicCustomer.getId().toString(), publicCustomer.getName());

return savedDashboard;
} catch (Exception e) {

logEntityAction(emptyId(EntityType.DASHBOARD), null,
null,
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);
null,
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);

throw handleException(e);
}
Expand All @@ -373,15 +387,15 @@ public Dashboard unassignDashboardFromPublicCustomer(@PathVariable(DASHBOARD_ID)
Dashboard savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(dashboardId, publicCustomer.getId()));

logEntityAction(dashboardId, dashboard,
publicCustomer.getId(),
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, publicCustomer.getId().toString(), publicCustomer.getName());
publicCustomer.getId(),
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, publicCustomer.getId().toString(), publicCustomer.getName());

return savedDashboard;
} catch (Exception e) {

logEntityAction(emptyId(EntityType.DASHBOARD), null,
null,
ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);
null,
ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);

throw handleException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void deleteWidgetType(@PathVariable("widgetTypeId") String strWidgetTypeI
}
}

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/widgetTypes", params = { "isSystem", "bundleAlias"}, method = RequestMethod.GET)
@ResponseBody
public List<WidgetType> getBundleWidgetTypes(
Expand Down
Loading

0 comments on commit 32ccd1d

Please sign in to comment.