Skip to content

Commit

Permalink
CST-5249 Restore OpenAIRE on user interfaces, QAAuthorizationFeature …
Browse files Browse the repository at this point in the history
…fix and IT java class
  • Loading branch information
frabacche committed Dec 15, 2023
1 parent f931a52 commit 0a74a94
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 5 deletions.
10 changes: 9 additions & 1 deletion dspace-api/src/main/java/org/dspace/content/QAEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ public class QAEvent {
private String source;

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;

/**
* evaluated with the targeted dspace object id
*
* */
private String target;

private String related;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public OpenaireRestToken grabNewAccessToken() throws IOException {

if (StringUtils.isBlank(tokenServiceUrl) || StringUtils.isBlank(clientId)
|| 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;
Expand Down
12 changes: 12 additions & 0 deletions dspace-api/src/test/java/org/dspace/builder/QAEventBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ public class QAEventBuilder extends AbstractBuilder<QAEvent, QAEventService> {
private Item item;
private QAEvent target;
private String source = QAEvent.OPENAIRE_SOURCE;
/**
* the title of the DSpace object
* */
private String title;
/**
* the name of the Quality Assurance Event Topic
* */
private String topic;
/**
* thr original QA Event imported
* */
private String message;
/**
* uuid of the targeted DSpace object
* */
private String relatedItem;
private double trust = 0.5;
private Date lastUpdate = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import org.dspace.app.rest.authorization.AuthorizationFeature;
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
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.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
Expand All @@ -28,6 +29,7 @@
public class QAAuthorizationFeature implements AuthorizationFeature {
public final static String NAME = "canSeeQA";

@Autowired
private ConfigurationService configurationService;

@Override
Expand All @@ -38,7 +40,7 @@ public boolean isAuthorized(Context context, BaseObjectRest object) throws SQLEx
@Override
public String[] getSupportedTypes() {
return new String[]{
QAEventRest.CATEGORY + "." + QAEventRest.NAME,
SiteRest.CATEGORY + "." + SiteRest.NAME
};
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
2 changes: 1 addition & 1 deletion dspace/config/crosswalks/oai/xoai.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
</Set>
<Set id="openaireSet">
<Spec>openaire</Spec>
<Name>Openaire</Name>
<Name>OpenAIRE</Name>
<!-- Just an alias -->
</Set>
</Sets>
Expand Down

0 comments on commit 0a74a94

Please sign in to comment.