Commit a003839a authored by SGupta79's avatar SGupta79
Browse files

Update the logs

parent 8f778707
Pipeline #24573 failed with stages
in 48 seconds
package org.opengroup.osdu.schema.api;
import javax.validation.Valid;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.BadRequestException;
......@@ -28,53 +30,68 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("schema")
public class SchemaController {
@Autowired
ISchemaService schemaService;
@Autowired
ISchemaService schemaService;
@Autowired
JaxRsDpsLog log;
@PostMapping()
@PreAuthorize("@authorizationFilter.hasRole('" + SchemaConstants.ENTITLEMENT_SERVICE_GROUP_EDITORS + "')")
public ResponseEntity<SchemaInfo> createSchema(@Valid @RequestBody SchemaRequest schemaRequest)
throws ApplicationException, BadRequestException {
return new ResponseEntity<>(schemaService.createSchema(schemaRequest), HttpStatus.CREATED);
}
@PostMapping()
@PreAuthorize("@authorizationFilter.hasRole('" + SchemaConstants.ENTITLEMENT_SERVICE_GROUP_EDITORS + "')")
public ResponseEntity<SchemaInfo> createSchema(@Valid @RequestBody SchemaRequest schemaRequest)
throws ApplicationException, BadRequestException {
log.info(String.format("Create schema request : %s", schemaRequest));
SchemaInfo schemaInfo = schemaService.createSchema(schemaRequest);
log.info(String.format("Create schema response : %s", schemaInfo));
return new ResponseEntity<>(schemaInfo, HttpStatus.CREATED);
}
@GetMapping("/{id}")
@PreAuthorize("@authorizationFilter.hasRole('" + SchemaConstants.ENTITLEMENT_SERVICE_GROUP_VIEWERS + "')")
public ResponseEntity<Object> getSchema(@PathVariable("id") String id)
throws ApplicationException, NotFoundException, BadRequestException {
return new ResponseEntity<>(schemaService.getSchema(id), HttpStatus.OK);
}
@GetMapping("/{id}")
@PreAuthorize("@authorizationFilter.hasRole('" + SchemaConstants.ENTITLEMENT_SERVICE_GROUP_VIEWERS + "')")
public ResponseEntity<Object> getSchema(@PathVariable("id") String id)
throws ApplicationException, NotFoundException, BadRequestException {
log.info(String.format("Get schema by id request : %s", id));
Object schema = schemaService.getSchema(id);
log.info(String.format("Get schema by id response : %s", schema));
return new ResponseEntity<>(schema, HttpStatus.OK);
}
@GetMapping()
@PreAuthorize("@authorizationFilter.hasRole('" + SchemaConstants.ENTITLEMENT_SERVICE_GROUP_VIEWERS + "')")
public ResponseEntity<SchemaInfoResponse> getSchemaInfoList(
@RequestParam(required = false, name = "authority") String authority,
@RequestParam(required = false, name = "source") String source,
@RequestParam(required = false, name = "entityType") String entityType,
@RequestParam(required = false, name = "schemaVersionMajor") Long schemaVersionMajor,
@RequestParam(required = false, name = "schemaVersionMinor") Long schemaVersionMinor,
@RequestParam(required = false, name = "schemaVersionPatch") Long schemaVersionPatch,
@RequestParam(required = false, name = "status") String status,
@RequestParam(required = false, name = "scope") String scope,
@RequestParam(required = false, name = "latestVersion") Boolean latestVersion,
@RequestParam(required = false, name = "limit", defaultValue = "100") int limit,
@RequestParam(required = false, name = "offset", defaultValue = "0") int offset)
throws ApplicationException, BadRequestException {
QueryParams queryParams = QueryParams.builder().authority(authority).source(source).entityType(entityType)
.schemaVersionMajor(schemaVersionMajor).schemaVersionMinor(schemaVersionMinor)
.schemaVersionPatch(schemaVersionPatch).limit(limit).offset(offset).scope(scope).status(status)
.latestVersion(latestVersion).build();
return new ResponseEntity<>(schemaService.getSchemaInfoList(queryParams), HttpStatus.OK);
}
@GetMapping()
@PreAuthorize("@authorizationFilter.hasRole('" + SchemaConstants.ENTITLEMENT_SERVICE_GROUP_VIEWERS + "')")
public ResponseEntity<SchemaInfoResponse> getSchemaInfoList(
@RequestParam(required = false, name = "authority") String authority,
@RequestParam(required = false, name = "source") String source,
@RequestParam(required = false, name = "entityType") String entityType,
@RequestParam(required = false, name = "schemaVersionMajor") Long schemaVersionMajor,
@RequestParam(required = false, name = "schemaVersionMinor") Long schemaVersionMinor,
@RequestParam(required = false, name = "schemaVersionPatch") Long schemaVersionPatch,
@RequestParam(required = false, name = "status") String status,
@RequestParam(required = false, name = "scope") String scope,
@RequestParam(required = false, name = "latestVersion") Boolean latestVersion,
@RequestParam(required = false, name = "limit", defaultValue = "100") int limit,
@RequestParam(required = false, name = "offset", defaultValue = "0") int offset)
throws ApplicationException, BadRequestException {
QueryParams queryParams = QueryParams.builder().authority(authority).source(source).entityType(entityType)
.schemaVersionMajor(schemaVersionMajor).schemaVersionMinor(schemaVersionMinor)
.schemaVersionPatch(schemaVersionPatch).limit(limit).offset(offset).scope(scope).status(status)
.latestVersion(latestVersion).build();
log.info(String.format("Get schema request : %s", queryParams));
SchemaInfoResponse schemaInfoResponse = schemaService.getSchemaInfoList(queryParams);
log.info(String.format("Get schema response : %s", schemaInfoResponse));
return new ResponseEntity<>(schemaInfoResponse, HttpStatus.OK);
}
@PutMapping()
@PreAuthorize("@authorizationFilter.hasRole('" + SchemaConstants.ENTITLEMENT_SERVICE_GROUP_EDITORS + "')")
public ResponseEntity<SchemaInfo> upsertSchema(@Valid @RequestBody SchemaRequest schemaRequest)
throws ApplicationException, BadRequestException {
@PutMapping()
@PreAuthorize("@authorizationFilter.hasRole('" + SchemaConstants.ENTITLEMENT_SERVICE_GROUP_EDITORS + "')")
public ResponseEntity<SchemaInfo> upsertSchema(@Valid @RequestBody SchemaRequest schemaRequest)
throws ApplicationException, BadRequestException {
SchemaUpsertResponse upsertResp = schemaService.upsertSchema(schemaRequest);
ResponseEntity<SchemaInfo> response = new ResponseEntity<>(upsertResp.getSchemaInfo(), upsertResp.getHttpCode());
return response;
}
log.info(String.format("Put schema request : %s", schemaRequest));
SchemaUpsertResponse upsertResp = schemaService.upsertSchema(schemaRequest);
ResponseEntity<SchemaInfo> response = new ResponseEntity<>(upsertResp.getSchemaInfo(),
upsertResp.getHttpCode());
log.info(String.format("Put schema response : %s", upsertResp));
return response;
}
}
......@@ -9,6 +9,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.schema.enums.SchemaScope;
import org.opengroup.osdu.schema.enums.SchemaStatus;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
......@@ -30,6 +31,9 @@ public class SchemaControllerTest {
@Mock
ISchemaService schemaService;
@Mock
JaxRsDpsLog log;
@InjectMocks
SchemaController schemaController;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment