CST-5249 Restore OpenAIRE on user interfaces, QAAuthorizationFeature fix and IT java class

This commit is contained in:
frabacche
2023-12-15 16:41:48 +01:00
parent f931a52001
commit 0a74a941b0
6 changed files with 111 additions and 5 deletions

View File

@@ -34,9 +34,17 @@ public class QAEvent {
private String source; private String source;
private String eventId; private String eventId;
/**
* contains the targeted dspace object,
* ie: oai:www.openstarts.units.it:123456789/1120 contains the handle
* of the DSpace pbject in its final part 123456789/1120
* */
private String originalId; private String originalId;
/**
* evaluated with the targeted dspace object id
*
* */
private String target; private String target;
private String related; private String related;

View File

@@ -103,7 +103,7 @@ public class OpenaireRestConnector {
if (StringUtils.isBlank(tokenServiceUrl) || StringUtils.isBlank(clientId) if (StringUtils.isBlank(tokenServiceUrl) || StringUtils.isBlank(clientId)
|| StringUtils.isBlank(clientSecret)) { || StringUtils.isBlank(clientSecret)) {
throw new IOException("Cannot grab Openaire token with nulls service url, client id or secret"); throw new IOException("Cannot grab OpenAIRE token with nulls service url, client id or secret");
} }
String auth = clientId + ":" + clientSecret; String auth = clientId + ":" + clientSecret;

View File

@@ -25,9 +25,21 @@ public class QAEventBuilder extends AbstractBuilder<QAEvent, QAEventService> {
private Item item; private Item item;
private QAEvent target; private QAEvent target;
private String source = QAEvent.OPENAIRE_SOURCE; private String source = QAEvent.OPENAIRE_SOURCE;
/**
* the title of the DSpace object
* */
private String title; private String title;
/**
* the name of the Quality Assurance Event Topic
* */
private String topic; private String topic;
/**
* thr original QA Event imported
* */
private String message; private String message;
/**
* uuid of the targeted DSpace object
* */
private String relatedItem; private String relatedItem;
private double trust = 0.5; private double trust = 0.5;
private Date lastUpdate = new Date(); private Date lastUpdate = new Date();

View File

@@ -12,9 +12,10 @@ import java.sql.SQLException;
import org.dspace.app.rest.authorization.AuthorizationFeature; import org.dspace.app.rest.authorization.AuthorizationFeature;
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation; import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
import org.dspace.app.rest.model.BaseObjectRest; import org.dspace.app.rest.model.BaseObjectRest;
import org.dspace.app.rest.model.QAEventRest; import org.dspace.app.rest.model.SiteRest;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.services.ConfigurationService; import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -28,6 +29,7 @@ import org.springframework.stereotype.Component;
public class QAAuthorizationFeature implements AuthorizationFeature { public class QAAuthorizationFeature implements AuthorizationFeature {
public final static String NAME = "canSeeQA"; public final static String NAME = "canSeeQA";
@Autowired
private ConfigurationService configurationService; private ConfigurationService configurationService;
@Override @Override
@@ -38,7 +40,7 @@ public class QAAuthorizationFeature implements AuthorizationFeature {
@Override @Override
public String[] getSupportedTypes() { public String[] getSupportedTypes() {
return new String[]{ return new String[]{
QAEventRest.CATEGORY + "." + QAEventRest.NAME, SiteRest.CATEGORY + "." + SiteRest.NAME
}; };
} }
} }

View File

@@ -0,0 +1,84 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.authorization;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.dspace.app.rest.authorization.impl.QAAuthorizationFeature;
import org.dspace.app.rest.converter.SiteConverter;
import org.dspace.app.rest.matcher.AuthorizationMatcher;
import org.dspace.app.rest.model.SiteRest;
import org.dspace.app.rest.projection.DefaultProjection;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.content.Site;
import org.dspace.content.service.SiteService;
import org.dspace.services.ConfigurationService;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Test suite for the Quality Assurance Authorization feature
*
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
*
*/
public class QAAuthorizationFeatureIT extends AbstractControllerIntegrationTest {
@Autowired
private AuthorizationFeatureService authorizationFeatureService;
@Autowired
private SiteService siteService;
@Autowired
private SiteConverter siteConverter;
@Autowired
private ConfigurationService configurationService;
private AuthorizationFeature qaAuthorizationFeature;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
context.turnOffAuthorisationSystem();
qaAuthorizationFeature = authorizationFeatureService.find(QAAuthorizationFeature.NAME);
context.restoreAuthSystemState();
}
@Test
public void testQAAuthorizationSuccess() throws Exception {
configurationService.setProperty("qaevents.enabled", true);
Site site = siteService.findSite(context);
SiteRest siteRest = siteConverter.convert(site, DefaultProjection.DEFAULT);
String tokenAdmin = getAuthToken(admin.getEmail(), password);
Authorization authAdminSite = new Authorization(admin, qaAuthorizationFeature, siteRest);
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + authAdminSite.getID()))
.andExpect(jsonPath("$", Matchers.is(
AuthorizationMatcher.matchAuthorization(authAdminSite))));
}
@Test
public void testQAAuthorizationFail() throws Exception {
configurationService.setProperty("qaevents.enabled", false);
Site site = siteService.findSite(context);
SiteRest siteRest = siteConverter.convert(site, DefaultProjection.DEFAULT);
String tokenAdmin = getAuthToken(admin.getEmail(), password);
Authorization authAdminSite = new Authorization(admin, qaAuthorizationFeature, siteRest);
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + authAdminSite.getID()))
.andExpect(status().isNotFound());
}
}

View File

@@ -526,7 +526,7 @@
</Set> </Set>
<Set id="openaireSet"> <Set id="openaireSet">
<Spec>openaire</Spec> <Spec>openaire</Spec>
<Name>Openaire</Name> <Name>OpenAIRE</Name>
<!-- Just an alias --> <!-- Just an alias -->
</Set> </Set>
</Sets> </Sets>