"description": "Information type is not found",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
},
- "406": {
+ "409": {
"description": "The Information type has one or several active producers",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
}
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Void"}}}
},
"400": {
- "description": "Bad request",
+ "description": "Input validation failed",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
}
},
"description": "Producer created",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Void"}}}
},
+ "400": {
+ "description": "Input validation failed",
+ "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
+ },
"404": {
- "description": "Producer not found",
+ "description": "Producer type not found",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
}
},
"description": "Job created",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Void"}}}
},
+ "400": {
+ "description": "Input validation failed",
+ "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
+ },
"404": {
"description": "Enrichment Information type is not found",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
+ },
+ "409": {
+ "description": "Cannot modify job type",
+ "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
}
},
"parameters": [{
"description": "Job created",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Void"}}}
},
+ "400": {
+ "description": "Input validation failed",
+ "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
+ },
"404": {
"description": "Information type is not found",
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
+ },
+ "409": {
+ "description": "Cannot modify job type",
+ "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
}
},
"parameters": [
schema:
$ref: '#/components/schemas/Void'
400:
- description: Bad request
+ description: Input validation failed
content:
application/json:
schema:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetails'
- 406:
+ 409:
description: The Information type has one or several active producers
content:
application/json:
application/json:
schema:
$ref: '#/components/schemas/Void'
+ 400:
+ description: Input validation failed
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ProblemDetails'
404:
- description: Producer not found
+ description: Producer type not found
content:
application/json:
schema:
application/json:
schema:
$ref: '#/components/schemas/Void'
+ 400:
+ description: Input validation failed
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ProblemDetails'
404:
description: Enrichment Information type is not found
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetails'
+ 409:
+ description: Cannot modify job type
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ProblemDetails'
delete:
tags:
- A1-EI (registration)
application/json:
schema:
$ref: '#/components/schemas/Void'
+ 400:
+ description: Input validation failed
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ProblemDetails'
404:
description: Information type is not found
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetails'
+ 409:
+ description: Cannot modify job type
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ProblemDetails'
delete:
tags:
- Data consumer
@ApiResponse(
responseCode = "404",
description = "Enrichment Information type is not found", //
- content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))) //
+ content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))),
+ @ApiResponse(
+ responseCode = "400",
+ description = "Input validation failed", //
+ content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))), //
+ @ApiResponse(
+ responseCode = "409",
+ description = "Cannot modify job type", //
+ content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class)))
+
})
+
public Mono<ResponseEntity<Object>> putIndividualEiJob( //
@PathVariable("eiJobId") String eiJobId, //
@RequestBody A1eEiJobInfo eiJobObject) {
.flatMap(this::startEiJob) //
.doOnNext(newEiJob -> this.eiJobs.put(newEiJob)) //
.flatMap(newEiJob -> Mono.just(new ResponseEntity<>(isNewJob ? HttpStatus.CREATED : HttpStatus.OK)))
- .onErrorResume(throwable -> Mono.just(ErrorResponse.create(throwable, HttpStatus.NOT_FOUND)));
+ .onErrorResume(throwable -> Mono.just(ErrorResponse.create(throwable, HttpStatus.INTERNAL_SERVER_ERROR)));
}
private Mono<InfoJob> startEiJob(InfoJob newEiJob) {
if (url != null && !url.isEmpty()) {
URI uri = new URI(url);
if (!uri.isAbsolute()) {
- throw new ServiceException("URI: " + url + " is not absolute", HttpStatus.CONFLICT);
+ throw new ServiceException("URI: " + url + " is not absolute", HttpStatus.BAD_REQUEST);
}
}
}
JSONObject json = new JSONObject(objectAsString);
schema.validate(json);
} catch (Exception e) {
- throw new ServiceException("Json validation failure " + e.toString(), HttpStatus.CONFLICT);
+ throw new ServiceException("Json validation failure " + e.toString(), HttpStatus.BAD_REQUEST);
}
}
}
@ApiResponse(
responseCode = "404",
description = "Information type is not found", //
- content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))) //
- })
+ content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))), //
+ @ApiResponse(
+ responseCode = "400",
+ description = "Input validation failed", //
+ content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))), //
+ @ApiResponse(
+ responseCode = "409",
+ description = "Cannot modify job type", //
+ content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class)))})
public Mono<ResponseEntity<Object>> putIndividualInfoJob( //
@PathVariable("infoJobId") String jobId, //
@Parameter(
if (url != null && !url.isEmpty()) {
URI uri = new URI(url);
if (!uri.isAbsolute()) {
- throw new ServiceException("URI: " + url + " is not absolute", HttpStatus.CONFLICT);
+ throw new ServiceException("URI: " + url + " is not absolute", HttpStatus.BAD_REQUEST);
}
}
}
JSONObject json = new JSONObject(objectAsString);
schema.validate(json);
} catch (Exception e) {
- throw new ServiceException("Json validation failure " + e.toString(), HttpStatus.CONFLICT);
+ throw new ServiceException("Json validation failure " + e.toString(), HttpStatus.BAD_REQUEST);
}
}
}
content = @Content(schema = @Schema(implementation = VoidResponse.class))), //
@ApiResponse(
responseCode = "400",
- description = "Bad request", //
+ description = "Input validation failed", //
content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class)))})
@Operation(summary = "Individual Information Type", description = "")
public ResponseEntity<Object> putInfoType( //
description = "Information type is not found", //
content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))), //
@ApiResponse(
- responseCode = "406",
+ responseCode = "409",
description = "The Information type has one or several active producers", //
content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))) //
})
}
if (!this.infoProducers.getProducersForType(type).isEmpty()) {
String firstProducerId = this.infoProducers.getProducersForType(type).iterator().next().getId();
- return ErrorResponse.create("The type has active producers: " + firstProducerId, HttpStatus.NOT_ACCEPTABLE);
+ return ErrorResponse.create("The type has active producers: " + firstProducerId, HttpStatus.CONFLICT);
}
this.infoTypes.remove(type);
infoJobs.getJobsForType(type).forEach(job -> infoJobs.remove(job, infoProducers)); // Delete jobs for the type
content = @Content(schema = @Schema(implementation = VoidResponse.class))), //
@ApiResponse(
responseCode = "404",
- description = "Producer not found", //
+ description = "Producer type not found", //
+ content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))), //
+ @ApiResponse(
+ responseCode = "400",
+ description = "Input validation failed", //
content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))) //
})
public ResponseEntity<Object> putInfoProducer( //
InfoProducer previousDefinition = this.infoProducers.get(infoProducerId);
this.infoProducers.registerProducer(toProducerRegistrationInfo(infoProducerId, registrationInfo));
return new ResponseEntity<>(previousDefinition == null ? HttpStatus.CREATED : HttpStatus.OK);
- } catch (Exception e) {
- return ErrorResponse.create(e, HttpStatus.NOT_FOUND);
+ } catch (ServiceException e) {
+ return ErrorResponse.create(e, e.getHttpStatus());
}
}
- private void validateUri(String url) throws URISyntaxException, ServiceException {
+ private void validateUri(String url) throws ServiceException {
if (url != null && !url.isEmpty()) {
- URI uri = new URI(url);
- if (!uri.isAbsolute()) {
- throw new ServiceException("URI: " + url + " is not absolute", HttpStatus.CONFLICT);
+ try {
+ URI uri = new URI(url);
+ if (!uri.isAbsolute()) {
+ throw new ServiceException("URI: " + url + " is not absolute", HttpStatus.BAD_REQUEST);
+ }
+ } catch (URISyntaxException e) {
+ throw new ServiceException(e.getMessage(), HttpStatus.BAD_REQUEST);
}
} else {
- throw new ServiceException("Missing required URL", HttpStatus.CONFLICT);
+ throw new ServiceException("Missing required URL", HttpStatus.BAD_REQUEST);
}
}
final InfoProducer producer = this.infoProducers.getProducer(infoProducerId);
this.infoProducers.deregisterProducer(producer);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
- } catch (Exception e) {
- return ErrorResponse.create(e, HttpStatus.NOT_FOUND);
+ } catch (ServiceException e) {
+ return ErrorResponse.create(e, e.getHttpStatus());
}
}
@Getter
private final HttpStatus httpStatus;
- public ServiceException(String message) {
- super(message);
- this.httpStatus = null;
- }
-
public ServiceException(String message, Exception originalException) {
super(message, originalException);
this.httpStatus = null;
import org.oransc.enrichment.exceptions.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
import org.springframework.util.FileSystemUtils;
/**
public synchronized InfoJob getJob(String id) throws ServiceException {
InfoJob ric = allEiJobs.get(id);
if (ric == null) {
- throw new ServiceException("Could not find Information job: " + id);
+ throw new ServiceException("Could not find Information job: " + id, HttpStatus.NOT_FOUND);
}
return ric;
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
public synchronized InfoProducer getProducer(String id) throws ServiceException {
InfoProducer p = allEiProducers.get(id);
if (p == null) {
- throw new ServiceException("Could not find Information Producer: " + id);
+ throw new ServiceException("Could not find Information Producer: " + id, HttpStatus.NOT_FOUND);
}
return p;
}
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpStatus;
import org.springframework.util.FileSystemUtils;
import reactor.core.publisher.Flux;
public synchronized SubscriptionInfo getSubscription(String id) throws ServiceException {
SubscriptionInfo p = allSubscriptions.get(id);
if (p == null) {
- throw new ServiceException("Could not find Information subscription: " + id);
+ throw new ServiceException("Could not find Information subscription: " + id, HttpStatus.NOT_FOUND);
}
return p;
}
private Mono<String> error() {
return Mono.error(new ServiceException(
- "No notifyTypeRegistered handler found for interface version " + apiVersion));
+ "No notifyTypeRegistered handler found for interface version " + apiVersion,
+ HttpStatus.INTERNAL_SERVER_ERROR));
}
};
}
import org.oransc.enrichment.exceptions.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
import org.springframework.util.FileSystemUtils;
/**
public synchronized InfoType getType(String id) throws ServiceException {
InfoType type = allEiTypes.get(id);
if (type == null) {
- throw new ServiceException("Information type not found: " + id);
+ throw new ServiceException("Information type not found: " + id, HttpStatus.NOT_FOUND);
}
return type;
}
"targetUri", "jobStatusUrl");
String body = gson.toJson(jobInfo);
- testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "Json validation failure");
+ testErrorCode(restClient().put(url, body), HttpStatus.BAD_REQUEST, "Json validation failure");
+
+ testErrorCode(restClient().put(url, "{jojo}"), HttpStatus.BAD_REQUEST, "", false);
+
}
@Test
new ConsumerJobInfo("typeId", jsonObject("{ \"XXstring\" : \"value\" }"), "owner", "targetUri", null);
String body = gson.toJson(jobInfo);
- testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "Json validation failure");
+ testErrorCode(restClient().put(url, body), HttpStatus.BAD_REQUEST, "Json validation failure");
}
@Test
ConsumerJobInfo jobInfo = new ConsumerJobInfo(TYPE_ID, jsonObject(), "owner", "junk", null);
String body = gson.toJson(jobInfo);
- testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "URI: junk is not absolute");
+ testErrorCode(restClient().put(url, body), HttpStatus.BAD_REQUEST, "URI: junk is not absolute");
}
@Test
String url = ProducerConsts.API_ROOT + "/info-types/" + TYPE_ID;
String body = "{}";
testErrorCode(restClient().put(url, body), HttpStatus.BAD_REQUEST, "No schema provided");
+
+ testErrorCode(restClient().post(url, body), HttpStatus.METHOD_NOT_ALLOWED, "", false);
}
@Test
void producerDeleteEiTypeExistingProducer() throws Exception {
putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
String url = ProducerConsts.API_ROOT + "/info-types/" + TYPE_ID;
- testErrorCode(restClient().delete(url), HttpStatus.NOT_ACCEPTABLE,
- "The type has active producers: " + PRODUCER_ID);
+ testErrorCode(restClient().delete(url), HttpStatus.CONFLICT, "The type has active producers: " + PRODUCER_ID);
assertThat(this.infoTypes.size()).isEqualTo(1);
}