Skip to content

Commit 2f4c3c5

Browse files
authored
Merge pull request #78 from FAIRDataTeam/hotfix/1.2.1
Hotfix 1.2.1
2 parents 11909c1 + 15470f1 commit 2f4c3c5

File tree

9 files changed

+96
-139
lines changed

9 files changed

+96
-139
lines changed

.mvn/maven.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
-Drevision=1.2.0
1+
-Drevision=1.2.1
22
-Dchangelist=.develop

src/main/java/nl/dtls/fairdatapoint/api/controller/dashboard/DashboardController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import nl.dtls.fairdatapoint.service.metadata.exception.MetadataServiceException;
2828
import org.eclipse.rdf4j.model.IRI;
2929
import org.springframework.beans.factory.annotation.Autowired;
30+
import org.springframework.beans.factory.annotation.Value;
3031
import org.springframework.http.HttpStatus;
3132
import org.springframework.http.ResponseEntity;
3233
import org.springframework.web.bind.annotation.RequestMapping;
@@ -44,12 +45,16 @@
4445
@RequestMapping("/dashboard")
4546
public class DashboardController {
4647

48+
@Value("${instance.url}")
49+
private String instanceUrl;
50+
51+
4752
@Autowired
4853
private DashboardService dashboardService;
4954

5055
@RequestMapping(method = RequestMethod.GET)
5156
public ResponseEntity<List<DashboardItemDTO>> getDashboard(HttpServletRequest request) throws MetadataServiceException {
52-
IRI uri = i(getRequestURL(request));
57+
IRI uri = i(getRequestURL(request, instanceUrl));
5358
IRI repositoryUri = removeLastPartOfIRI(uri);
5459
List<DashboardItemDTO> dto = dashboardService.getDashboard(repositoryUri);
5560
return new ResponseEntity<>(dto, HttpStatus.OK);

src/main/java/nl/dtls/fairdatapoint/api/controller/metadata/GenericController.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
package nl.dtls.fairdatapoint.api.controller.metadata;
2424

25-
import nl.dtls.fairdatapoint.entity.exception.ResourceNotFoundException;
25+
import nl.dtls.fairdatapoint.entity.exception.ValidationException;
2626
import nl.dtls.fairdatapoint.entity.resource.ResourceDefinition;
2727
import nl.dtls.fairdatapoint.service.metadata.common.MetadataService;
2828
import nl.dtls.fairdatapoint.service.metadata.exception.MetadataServiceException;
@@ -35,6 +35,7 @@
3535
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
3636
import org.eclipse.rdf4j.rio.RDFFormat;
3737
import org.springframework.beans.factory.annotation.Autowired;
38+
import org.springframework.beans.factory.annotation.Value;
3839
import org.springframework.http.ResponseEntity;
3940
import org.springframework.web.bind.annotation.*;
4041

@@ -53,6 +54,9 @@
5354
@RequestMapping("/")
5455
public class GenericController {
5556

57+
@Value("${instance.url}")
58+
private String instanceUrl;
59+
5660
@Autowired
5761
private MetadataServiceFactory metadataServiceFactory;
5862

@@ -73,7 +77,7 @@ public Model getFormMetadata() {
7377
produces = {"!application/json"})
7478
public Model getMetaData(HttpServletRequest request) throws MetadataServiceException {
7579
// 1. Init
76-
String uri = getRequestURL(request);
80+
String uri = getRequestURL(request, instanceUrl);
7781
Model resultRdf = new LinkedHashModel();
7882
String urlPrefix = getResourceNameForDetail(uri);
7983
MetadataService metadataService = metadataServiceFactory.getMetadataServiceByUrlPrefix(urlPrefix);
@@ -82,7 +86,7 @@ public Model getMetaData(HttpServletRequest request) throws MetadataServiceExcep
8286
ResourceDefinition rd = resourceDefinitionService.getByUriPrefix(urlPrefix);
8387

8488
// 3. Get entity
85-
IRI entityUri = i(getRequestURL(request));
89+
IRI entityUri = i(getRequestURL(request, instanceUrl));
8690
Model entity = metadataService.retrieve(entityUri);
8791
resultRdf.addAll(entity);
8892

@@ -119,12 +123,12 @@ public ResponseEntity<Model> storeMetaData(HttpServletRequest request,
119123
@RequestHeader(value = "Content-Type", required = false) String contentType)
120124
throws MetadataServiceException {
121125
// 1. Init
122-
String urlPrefix = getResourceNameForList(getRequestURL(request));
126+
String urlPrefix = getResourceNameForList(getRequestURL(request, instanceUrl));
123127
MetadataService metadataService = metadataServiceFactory.getMetadataServiceByUrlPrefix(urlPrefix);
124128
ResourceDefinition rd = resourceDefinitionService.getByUriPrefix(urlPrefix);
125129

126130
// 2. Generate URI
127-
IRI uri = generateNewIRI(request);
131+
IRI uri = generateNewIRI(request, instanceUrl);
128132

129133
// 3. Parse reqDto
130134
RDFFormat rdfContentType = getRdfContentType(contentType);
@@ -153,12 +157,12 @@ public ResponseEntity<Model> updateMetaData(HttpServletRequest request,
153157
@RequestHeader(value = "Content-Type", required = false) String contentType)
154158
throws MetadataServiceException {
155159
// 1. Init
156-
String urlPrefix = getResourceNameForDetail(getRequestURL(request));
160+
String urlPrefix = getResourceNameForDetail(getRequestURL(request, instanceUrl));
157161
MetadataService metadataService = metadataServiceFactory.getMetadataServiceByUrlPrefix(urlPrefix);
158162
ResourceDefinition rd = resourceDefinitionService.getByUriPrefix(urlPrefix);
159163

160164
// 2. Extract URI
161-
IRI uri = i(getRequestURL(request));
165+
IRI uri = i(getRequestURL(request, instanceUrl));
162166

163167
// 3. Parse reqDto
164168
RDFFormat rdfContentType = getRdfContentType(contentType);
@@ -179,7 +183,7 @@ public ResponseEntity<Model> updateMetaData(HttpServletRequest request,
179183
@RequestMapping(value = "**", method = RequestMethod.DELETE)
180184
public ResponseEntity<Void> deleteMetadata(HttpServletRequest request) throws MetadataServiceException {
181185
// 1. Init
182-
String urlPrefix = getResourceNameForDetail(getRequestURL(request));
186+
String urlPrefix = getResourceNameForDetail(getRequestURL(request, instanceUrl));
183187
MetadataService metadataService = metadataServiceFactory.getMetadataServiceByUrlPrefix(urlPrefix);
184188
ResourceDefinition rd = resourceDefinitionService.getByUriPrefix(urlPrefix);
185189

@@ -189,7 +193,7 @@ public ResponseEntity<Void> deleteMetadata(HttpServletRequest request) throws Me
189193
}
190194

191195
// 3. Extract URI
192-
IRI uri = i(getRequestURL(request));
196+
IRI uri = i(getRequestURL(request, instanceUrl));
193197

194198
// 4. Store metadata
195199
metadataService.delete(uri, rd);
@@ -199,22 +203,30 @@ public ResponseEntity<Void> deleteMetadata(HttpServletRequest request) throws Me
199203
}
200204

201205
private String getResourceNameForList(String url) {
206+
instanceUrl = removeLastSlash(instanceUrl);
207+
url = url.replace(instanceUrl, "");
208+
202209
String[] parts = url.split("/");
203-
if (parts.length != 4) {
204-
throw new ResourceNotFoundException("Unsupported URL");
210+
if (parts.length != 2) {
211+
throw new ValidationException("Unsupported URL");
205212
}
206-
return parts[3];
213+
return parts[1];
207214
}
208215

209216
private String getResourceNameForDetail(String url) {
210-
String[] parts = url.split("/");
211-
if (parts.length == 3) {
217+
instanceUrl = removeLastSlash(instanceUrl);
218+
url = url.replace(instanceUrl, "");
219+
220+
// If URL is a repository -> return empty string
221+
if (url.equals("")) {
212222
return "";
213223
}
214-
if (parts.length != 5) {
215-
throw new ResourceNotFoundException("Unsupported URL");
224+
225+
String[] parts = url.split("/");
226+
if (parts.length != 3) {
227+
throw new ValidationException("Unsupported URL");
216228
}
217-
return parts[3];
229+
return parts[1];
218230
}
219231

220232
}

src/main/java/nl/dtls/fairdatapoint/api/controller/metadata/GenericMemberController.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.eclipse.rdf4j.model.IRI;
3434
import org.eclipse.rdf4j.model.Model;
3535
import org.springframework.beans.factory.annotation.Autowired;
36+
import org.springframework.beans.factory.annotation.Value;
3637
import org.springframework.http.HttpStatus;
3738
import org.springframework.http.ResponseEntity;
3839
import org.springframework.web.bind.annotation.*;
@@ -50,6 +51,10 @@
5051
@RestController
5152
public class GenericMemberController {
5253

54+
@Value("${instance.url}")
55+
private String instanceUrl;
56+
57+
5358
@Autowired
5459
private MemberService memberService;
5560

@@ -58,7 +63,7 @@ public class GenericMemberController {
5863

5964
@RequestMapping(value = "**/member", method = RequestMethod.GET)
6065
public MemberDTO getMember(HttpServletRequest request) {
61-
String uri = getRequestURL(request);
66+
String uri = getRequestURL(request, instanceUrl);
6267
String entityId = removeLastPartOfIRI(i(uri)).getLocalName();
6368
Optional<MemberDTO> oMember = memberService.getMemberForCurrentUser(entityId, Metadata.class);
6469
return oMember.orElse(new MemberDTO(null, null));
@@ -68,11 +73,11 @@ public MemberDTO getMember(HttpServletRequest request) {
6873
public ResponseEntity<List<MemberDTO>> getMembers(HttpServletRequest request)
6974
throws ResourceNotFoundException, MetadataServiceException {
7075
// 1. Init
71-
String urlPrefix = getResourceNameForList(getRequestURL(request));
76+
String urlPrefix = getResourceNameForList(getRequestURL(request, instanceUrl));
7277
MetadataService metadataService = metadataServiceFactory.getMetadataServiceByUrlPrefix(urlPrefix);
7378

7479
// 2. Get entity
75-
IRI uri = i(getRequestURL(request));
80+
IRI uri = i(getRequestURL(request, instanceUrl));
7681
IRI entityUri = removeLastPartOfIRI(uri);
7782
Model metadata = metadataService.retrieve(entityUri);
7883

@@ -86,11 +91,11 @@ public ResponseEntity<List<MemberDTO>> getMembers(HttpServletRequest request)
8691
public Object putMember(@PathVariable final String userUuid, HttpServletRequest request,
8792
@RequestBody @Valid MemberCreateDTO reqBody) throws MetadataServiceException {
8893
// 1. Init
89-
String urlPrefix = getResourceNameForDetail(getRequestURL(request));
94+
String urlPrefix = getResourceNameForDetail(getRequestURL(request, instanceUrl));
9095
MetadataService metadataService = metadataServiceFactory.getMetadataServiceByUrlPrefix(urlPrefix);
9196

9297
// 2. Get entity
93-
IRI uri = i(getRequestURL(request));
98+
IRI uri = i(getRequestURL(request, instanceUrl));
9499
IRI entityUri = removeLastPartOfIRI(removeLastPartOfIRI(uri));
95100
Model metadata = metadataService.retrieve(entityUri);
96101

@@ -105,11 +110,11 @@ public Object putMember(@PathVariable final String userUuid, HttpServletRequest
105110
public ResponseEntity deleteMember(@PathVariable final String userUuid, HttpServletRequest request)
106111
throws ResourceNotFoundException, MetadataServiceException {
107112
// 1. Init
108-
String urlPrefix = getResourceNameForDetail(getRequestURL(request));
113+
String urlPrefix = getResourceNameForDetail(getRequestURL(request, instanceUrl));
109114
MetadataService metadataService = metadataServiceFactory.getMetadataServiceByUrlPrefix(urlPrefix);
110115

111116
// 2. Get entity
112-
IRI uri = i(getRequestURL(request));
117+
IRI uri = i(getRequestURL(request, instanceUrl));
113118
IRI entityUri = removeLastPartOfIRI(removeLastPartOfIRI(uri));
114119
Model metadata = metadataService.retrieve(entityUri);
115120

src/main/java/nl/dtls/fairdatapoint/config/MetadataConfig.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@
2727
import nl.dtls.fairdatapoint.service.pid.PurlPIDSystemImpl;
2828
import nl.dtls.fairmetadata4j.model.Agent;
2929
import org.eclipse.rdf4j.model.IRI;
30-
import org.eclipse.rdf4j.model.ValueFactory;
31-
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
3230
import org.springframework.beans.factory.annotation.Qualifier;
3331
import org.springframework.beans.factory.annotation.Value;
3432
import org.springframework.context.annotation.Bean;
3533
import org.springframework.context.annotation.Configuration;
3634

35+
import static nl.dtls.fairdatapoint.util.HttpUtil.removeLastSlash;
36+
import static nl.dtls.fairmetadata4j.util.ValueFactoryHelper.i;
37+
import static nl.dtls.fairmetadata4j.util.ValueFactoryHelper.l;
38+
3739
@Configuration
3840
public class MetadataConfig {
3941

40-
private final ValueFactory VALUEFACTORY = SimpleValueFactory.getInstance();
41-
4242
@Bean(name = "publisher")
4343
public Agent publisher(@Value("${metadataProperties.publisherURI:}") String publisherURI,
4444
@Value("${metadataProperties.publisherName:}") String publishername) {
4545

4646
Agent publisher = null;
4747
if (!publisherURI.isEmpty() && !publishername.isEmpty()) {
4848
publisher = new Agent();
49-
publisher.setUri(VALUEFACTORY.createIRI(publisherURI));
50-
publisher.setName(VALUEFACTORY.createLiteral(publishername));
49+
publisher.setUri(i(publisherURI));
50+
publisher.setName(l(publishername));
5151
}
5252
return publisher;
5353
}
@@ -57,7 +57,7 @@ public IRI language(@Value("${metadataProperties.language:}") String languageURI
5757

5858
IRI language = null;
5959
if (!languageURI.isEmpty()) {
60-
language = VALUEFACTORY.createIRI(languageURI);
60+
language = i(languageURI);
6161
}
6262
return language;
6363
}
@@ -67,7 +67,7 @@ public IRI license(@Value("${metadataProperties.license:}") String licenseURI) {
6767

6868
IRI license = null;
6969
if (!licenseURI.isEmpty()) {
70-
license = VALUEFACTORY.createIRI(licenseURI);
70+
license = i(licenseURI);
7171
}
7272
return license;
7373
}
@@ -85,11 +85,7 @@ public PIDSystem pidSystem(@Value("${pidSystem.type:1}") int pidSystemtype,
8585

8686
@Bean
8787
public IRI purlBaseUrl(@Value("${pidSystem.purl.baseUrl:}") String url) {
88-
String baseUrl = url;
89-
if (baseUrl.endsWith("/")) {
90-
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
91-
}
92-
return VALUEFACTORY.createIRI(baseUrl);
88+
return i(removeLastSlash(url));
9389
}
9490

9591
}

src/main/java/nl/dtls/fairdatapoint/config/RepositoryConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
import java.io.File;
4343

44+
import static nl.dtls.fairdatapoint.util.HttpUtil.removeLastSlash;
45+
4446
@Configuration
4547
@Log4j2
4648
public class RepositoryConfig {
@@ -135,9 +137,7 @@ private Repository getAgraphRepository() {
135137
private Repository getBlazeGraphRepository() {
136138
log.info("Setting up Blaze Graph Store");
137139
if (!blazegraphUrl.isEmpty()) {
138-
if (blazegraphUrl.endsWith("/")) {
139-
blazegraphUrl = blazegraphUrl.substring(0, blazegraphUrl.length() - 1);
140-
}
140+
blazegraphUrl = removeLastSlash(blazegraphUrl);
141141
// Build url for blazegraph (Eg: http://localhost:8079/bigdata/namespace/test1/sparql)
142142
StringBuilder sb = new StringBuilder();
143143
sb.append(blazegraphUrl);

src/main/java/nl/dtls/fairdatapoint/config/SwaggerConfig.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@
3636
import springfox.documentation.service.*;
3737
import springfox.documentation.spi.DocumentationType;
3838
import springfox.documentation.spi.service.contexts.SecurityContext;
39-
import springfox.documentation.spring.web.paths.RelativePathProvider;
4039
import springfox.documentation.spring.web.plugins.Docket;
4140
import springfox.documentation.swagger2.annotations.EnableSwagger2;
4241

4342
import javax.servlet.ServletContext;
4443
import java.util.Collections;
4544
import java.util.List;
4645

47-
import static nl.dtls.fairdatapoint.constant.EnvConstant.PUBLIC_PATH;
46+
import static nl.dtls.fairdatapoint.util.HttpUtil.removeProtocol;
4847

4948
@Configuration
5049
@EnableSwagger2
@@ -64,16 +63,9 @@ public Docket api() {
6463
.paths(PathSelectors.any())
6564
.build()
6665
.apiInfo(apiInfo())
67-
.host(instanceUrl)
66+
.host(removeProtocol(instanceUrl))
6867
.securitySchemes(List.of(apiKey()))
69-
.securityContexts(List.of(securityContext()))
70-
.pathProvider(new RelativePathProvider(servletContext) {
71-
@Override
72-
public String getApplicationBasePath() {
73-
String publicPath = System.getenv(PUBLIC_PATH);
74-
return publicPath;
75-
}
76-
});
68+
.securityContexts(List.of(securityContext()));
7769
}
7870

7971
private ApiInfo apiInfo() {
@@ -84,7 +76,7 @@ private ApiInfo apiInfo() {
8476
" FAIR Data Point Specification" +
8577
" </a>" +
8678
" <br/>",
87-
"1.2.0",
79+
"1.2.1",
8880
"ATO",
8981
new Contact("Luiz Bonino",
9082
"https://github.com/FAIRDataTeam/FAIRDataPoint",

src/main/java/nl/dtls/fairdatapoint/constant/EnvConstant.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)