mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
71424: Label always on UsageReportPoint for UI &
Tests fixed by adding null check on targetId in EvaluatorPlugins
This commit is contained in:
@@ -20,4 +20,10 @@ public class UsageReportPointCityRest extends UsageReportPointRest {
|
||||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
super.id = id;
|
||||
super.label = id;
|
||||
}
|
||||
}
|
||||
|
@@ -18,20 +18,16 @@ import org.dspace.statistics.util.LocationUtils;
|
||||
public class UsageReportPointCountryRest extends UsageReportPointRest {
|
||||
public static final String NAME = "country";
|
||||
|
||||
private String label;
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
super.label = label;
|
||||
super.id = LocationUtils.getCountryCode(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
super.id = id;
|
||||
this.label = LocationUtils.getCountryName(id);
|
||||
super.label = LocationUtils.getCountryName(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -20,4 +20,10 @@ public class UsageReportPointDateRest extends UsageReportPointRest {
|
||||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
super.id = id;
|
||||
super.label = id;
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@ package org.dspace.app.rest.model;
|
||||
public class UsageReportPointDsoTotalVisitsRest extends UsageReportPointRest {
|
||||
|
||||
private String type;
|
||||
private String label;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
@@ -26,12 +25,4 @@ public class UsageReportPointDsoTotalVisitsRest extends UsageReportPointRest {
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ public class UsageReportPointRest extends BaseObjectRest<String> {
|
||||
public static final String NAME = "point";
|
||||
public static final String CATEGORY = RestModel.STATISTICS;
|
||||
protected String id;
|
||||
protected String label;
|
||||
private Map<String, Integer> values;
|
||||
|
||||
public String getCategory() {
|
||||
@@ -57,4 +58,12 @@ public class UsageReportPointRest extends BaseObjectRest<String> {
|
||||
public void setValues(Map<String, Integer> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
||||
|
@@ -67,6 +67,8 @@ public class UsageReportService extends AbstractDSpaceRestRepository {
|
||||
public static final String TOP_COUNTRIES_REPORT_ID = "TopCountries";
|
||||
public static final String TOP_CITIES_REPORT_ID = "TopCities";
|
||||
|
||||
public static final String SITE_WIDE_USAGE_REPORT_LABEL = "All of DSpace";
|
||||
|
||||
/**
|
||||
* Get list of usage reports that are applicable to the DSO (of given UUID)
|
||||
*
|
||||
@@ -164,7 +166,7 @@ public class UsageReportService extends AbstractDSpaceRestRepository {
|
||||
for (int i = 0; i < dataset.getColLabels().size(); i++) {
|
||||
UsageReportPointDsoTotalVisitsRest totalVisitPoint = new UsageReportPointDsoTotalVisitsRest();
|
||||
totalVisitPoint.setType("item");
|
||||
totalVisitPoint.setLabel(dataset.getColLabels().get(i));
|
||||
totalVisitPoint.setLabel(SITE_WIDE_USAGE_REPORT_LABEL);
|
||||
String urlOfItem = dataset.getColLabelsAttrs().get(i).get("url");
|
||||
DSpaceObject dso = handleService.resolveToObject(context, StringUtils.substringAfterLast(urlOfItem,
|
||||
"handle/"));
|
||||
@@ -193,7 +195,7 @@ public class UsageReportService extends AbstractDSpaceRestRepository {
|
||||
totalVisitPoint.setType(StringUtils.substringAfterLast(dso.getClass().getName().toLowerCase(), "."));
|
||||
totalVisitPoint.setId(dso.getID().toString());
|
||||
if (dataset.getColLabels().size() > 0) {
|
||||
totalVisitPoint.setLabel(dataset.getColLabels().get(0));
|
||||
totalVisitPoint.setLabel(dso.getName());
|
||||
totalVisitPoint.addValue("views", Integer.valueOf(dataset.getMatrix()[0][0]));
|
||||
} else {
|
||||
totalVisitPoint.setLabel(dso.getName());
|
||||
|
@@ -65,37 +65,39 @@ public class AuthorizeServicePermissionEvaluatorPlugin extends RestObjectPermiss
|
||||
Context context = ContextUtil.obtainContext(request.getServletRequest());
|
||||
EPerson ePerson = null;
|
||||
try {
|
||||
UUID dsoId = UUIDUtils.fromString(targetId.toString());
|
||||
DSpaceObjectService<DSpaceObject> dSpaceObjectService;
|
||||
try {
|
||||
dSpaceObjectService =
|
||||
if (targetId != null) {
|
||||
UUID dsoId = UUIDUtils.fromString(targetId.toString());
|
||||
DSpaceObjectService<DSpaceObject> dSpaceObjectService;
|
||||
try {
|
||||
dSpaceObjectService =
|
||||
contentServiceFactory.getDSpaceObjectService(Constants.getTypeID(targetType));
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// ok not a dspace object
|
||||
return false;
|
||||
}
|
||||
|
||||
ePerson = ePersonService.findByEmail(context, (String) authentication.getPrincipal());
|
||||
|
||||
if (dSpaceObjectService != null && dsoId != null) {
|
||||
DSpaceObject dSpaceObject = dSpaceObjectService.find(context, dsoId);
|
||||
|
||||
//If the dso is null then we give permission so we can throw another status code instead
|
||||
if (dSpaceObject == null) {
|
||||
return true;
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// ok not a dspace object
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the item is still inprogress we can process here only the READ permission.
|
||||
// Other actions need to be evaluated against the wrapper object (workspace or workflow item)
|
||||
if (dSpaceObject instanceof Item) {
|
||||
if (!DSpaceRestPermission.READ.equals(restPermission)
|
||||
&& !((Item) dSpaceObject).isArchived() && !((Item) dSpaceObject).isWithdrawn()) {
|
||||
return false;
|
||||
ePerson = ePersonService.findByEmail(context, (String) authentication.getPrincipal());
|
||||
|
||||
if (dSpaceObjectService != null && dsoId != null) {
|
||||
DSpaceObject dSpaceObject = dSpaceObjectService.find(context, dsoId);
|
||||
|
||||
//If the dso is null then we give permission so we can throw another status code instead
|
||||
if (dSpaceObject == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return authorizeService.authorizeActionBoolean(context, ePerson, dSpaceObject,
|
||||
// If the item is still inprogress we can process here only the READ permission.
|
||||
// Other actions need to be evaluated against the wrapper object (workspace or workflow item)
|
||||
if (dSpaceObject instanceof Item) {
|
||||
if (!DSpaceRestPermission.READ.equals(restPermission)
|
||||
&& !((Item) dSpaceObject).isArchived() && !((Item) dSpaceObject).isWithdrawn()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return authorizeService.authorizeActionBoolean(context, ePerson, dSpaceObject,
|
||||
restPermission.getDspaceApiActionId(), true);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
@@ -62,27 +62,29 @@ public class UsageReportRestPermissionEvaluatorPlugin extends RestObjectPermissi
|
||||
Request request = requestService.getCurrentRequest();
|
||||
Context context = ContextUtil.obtainContext(request.getServletRequest());
|
||||
UUID uuidObject = null;
|
||||
if (StringUtils.equalsIgnoreCase(UsageReportRest.NAME, targetType)) {
|
||||
if (StringUtils.countMatches(targetId.toString(), "_") != 1) {
|
||||
throw new IllegalArgumentException("Must end in objectUUID_reportId, example: " +
|
||||
"1911e8a4-6939-490c-b58b-a5d70f8d91fb_TopCountries");
|
||||
if (targetId != null) {
|
||||
if (StringUtils.equalsIgnoreCase(UsageReportRest.NAME, targetType)) {
|
||||
if (StringUtils.countMatches(targetId.toString(), "_") != 1) {
|
||||
throw new IllegalArgumentException("Must end in objectUUID_reportId, example: " +
|
||||
"1911e8a4-6939-490c-b58b-a5d70f8d91fb_TopCountries");
|
||||
}
|
||||
// Get uuid from uuidDSO_reportId pathParam
|
||||
uuidObject = UUID.fromString(StringUtils.substringBefore(targetId.toString(), "_"));
|
||||
} else if (StringUtils.equalsIgnoreCase(UsageReportRest.NAME + "search", targetType)) {
|
||||
// Get uuid from url (selfLink of dso) queryParam
|
||||
uuidObject = UUID.fromString(StringUtils.substringAfterLast(targetId.toString(), "/"));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// Get uuid from uuidDSO_reportId pathParam
|
||||
uuidObject = UUID.fromString(StringUtils.substringBefore(targetId.toString(), "_"));
|
||||
} else if (StringUtils.equalsIgnoreCase(UsageReportRest.NAME + "search", targetType)) {
|
||||
// Get uuid from url (selfLink of dso) queryParam
|
||||
uuidObject = UUID.fromString(StringUtils.substringAfterLast(targetId.toString(), "/"));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
DSpaceObject dso = dspaceObjectUtil.findDSpaceObject(context, uuidObject);
|
||||
if (dso == null) {
|
||||
throw new ResourceNotFoundException("No DSO found with this UUID: " + uuidObject);
|
||||
try {
|
||||
DSpaceObject dso = dspaceObjectUtil.findDSpaceObject(context, uuidObject);
|
||||
if (dso == null) {
|
||||
throw new ResourceNotFoundException("No DSO found with this UUID: " + uuidObject);
|
||||
}
|
||||
return authorizeService.authorizeActionBoolean(context, dso, restPermission.getDspaceApiActionId());
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return authorizeService.authorizeActionBoolean(context, dso, restPermission.getDspaceApiActionId());
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user