Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MODCON-api] - instanceIdentifier changed to instanceId #125

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public ResponseEntity<SharingInstance> getSharingInstanceById(UUID consortiumId,
}

@Override
public ResponseEntity<SharingInstanceCollection> getSharingInstances(UUID consortiumId, UUID instanceIdentifier,
public ResponseEntity<SharingInstanceCollection> getSharingInstances(UUID consortiumId, UUID instanceId,
String sourceTenantId, String targetTenantId, Status status, Integer offset, Integer limit) {
var centralTenantId = configurationService.getCentralTenantId(folioExecutionContext.getTenantId());
try (var ignored = new FolioExecutionContextSetter(prepareContextForTenant(centralTenantId, folioModuleMetadata, folioExecutionContext))) {
return ResponseEntity.ok(sharingInstanceService.getSharingInstances(consortiumId, instanceIdentifier, sourceTenantId,
return ResponseEntity.ok(sharingInstanceService.getSharingInstances(consortiumId, instanceId, sourceTenantId,
targetTenantId, status, offset, limit));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SharingInstanceConverter implements Converter<SharingInstanceEntity
public SharingInstance convert(SharingInstanceEntity source) {
SharingInstance sharingInstance = new SharingInstance();
sharingInstance.setId(source.getId());
sharingInstance.setInstanceIdentifier(source.getInstanceId());
sharingInstance.setInstanceId(source.getInstanceId());
sharingInstance.setSourceTenantId(source.getSourceTenantId());
sharingInstance.setTargetTenantId(source.getTargetTenantId());
sharingInstance.setStatus(source.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
public interface SharingInstanceRepository extends JpaRepository<SharingInstanceEntity, UUID>, JpaSpecificationExecutor<SharingInstanceEntity> {

interface Specifications {
static Specification<SharingInstanceEntity> constructSpecification(UUID instanceIdentifier, String sourceTenantId,
static Specification<SharingInstanceEntity> constructSpecification(UUID instanceId, String sourceTenantId,
String targetTenantId, Status status) {
var list = new ArrayList<Specification<SharingInstanceEntity>>();
if (Objects.nonNull(instanceIdentifier)) {
list.add(by("instanceId", instanceIdentifier));
if (Objects.nonNull(instanceId)) {
list.add(by("instanceId", instanceId));
}
if (StringUtils.isNotEmpty(sourceTenantId)) {
list.add(by("sourceTenantId", sourceTenantId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ public interface SharingInstanceService {
/**
* Get a sharing instance collection
* @param consortiumId the UUID of the consortium
* @param instanceIdentifier the UUID of the instance
* @param instanceId the UUID of the instance
* @param sourceTenantId the ID of the source tenant
* @param targetTenantId the ID of the target tenant
* @param status the status of the sharing instance
* @param offset the offset
* @param limit the limit
* @return the sharing instance collection
*/
SharingInstanceCollection getSharingInstances(UUID consortiumId, UUID instanceIdentifier, String sourceTenantId,
SharingInstanceCollection getSharingInstances(UUID consortiumId, UUID instanceId, String sourceTenantId,
String targetTenantId, Status status, Integer offset, Integer limit);

/**
* Update 'status' and 'error' fields of sharingInstance according to Kafka message payload
* @param promotingEvent contains 'instanceIdentifier', 'sourceTenantId', 'targetTenantId', and 'error'
* @param promotingEvent contains 'instanceId', 'sourceTenantId', 'targetTenantId', and 'error'
*/
void completePromotingLocalInstance(String promotingEvent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public SharingInstance getById(UUID consortiumId, UUID actionId) {
@SneakyThrows
@Transactional
public SharingInstance start(UUID consortiumId, SharingInstance sharingInstance) {
log.debug("start:: Trying to start instance sharing with instanceIdentifier: {}, consortiumId: {}", sharingInstance.getInstanceIdentifier(), consortiumId);
log.debug("start:: Trying to start instance sharing with instanceId: {}, consortiumId: {}", sharingInstance.getInstanceId(), consortiumId);
consortiumService.checkConsortiumExistsOrThrow(consortiumId);

String centralTenantId = tenantService.getCentralTenantId();
Expand All @@ -78,14 +78,14 @@ public SharingInstance start(UUID consortiumId, SharingInstance sharingInstance)
if (Objects.equals(centralTenantId, sourceTenantId)) {
JsonNode inventoryInstance;

try (var context = new FolioExecutionContextSetter(prepareContextForTenant(sourceTenantId, folioModuleMetadata, folioExecutionContext))) {
inventoryInstance = inventoryService.getById(sharingInstance.getInstanceIdentifier());
try (var ignored = new FolioExecutionContextSetter(prepareContextForTenant(sourceTenantId, folioModuleMetadata, folioExecutionContext))) {
inventoryInstance = inventoryService.getById(sharingInstance.getInstanceId());
} catch (Exception ex) {
log.error("start:: error when getting instance by id: {}", sharingInstance.getInstanceIdentifier(), ex);
log.error("start:: error when getting instance by id: {}", sharingInstance.getInstanceId(), ex);
return updateFieldsAndSaveInCaseOfException(sharingInstance, GET_INSTANCE_EXCEPTION_MSG, ex);
}

try (var context = new FolioExecutionContextSetter(prepareContextForTenant(targetTenantId, folioModuleMetadata, folioExecutionContext))) {
try (var ignored = new FolioExecutionContextSetter(prepareContextForTenant(targetTenantId, folioModuleMetadata, folioExecutionContext))) {
String source = switch (inventoryInstance.get("source").asText().toLowerCase()) {
case "folio" -> CONSORTIUM_FOLIO_INSTANCE_SOURCE;
case "marc" -> CONSORTIUM_MARC_INSTANCE_SOURCE;
Expand All @@ -94,7 +94,7 @@ public SharingInstance start(UUID consortiumId, SharingInstance sharingInstance)
var updatedInventoryInstance = ((ObjectNode) inventoryInstance).set("source", new TextNode(source));
inventoryService.saveInstance(updatedInventoryInstance);
} catch (Exception ex) {
log.error("start:: error when posting instance with id: {}", sharingInstance.getInstanceIdentifier(), ex);
log.error("start:: error when posting instance with id: {}", sharingInstance.getInstanceId(), ex);
return updateFieldsAndSaveInCaseOfException(sharingInstance, POST_INSTANCE_EXCEPTION_MSG, ex);
}

Expand All @@ -112,12 +112,12 @@ public SharingInstance start(UUID consortiumId, SharingInstance sharingInstance)
}

@Override
public SharingInstanceCollection getSharingInstances(UUID consortiumId, UUID instanceIdentifier, String sourceTenantId,
public SharingInstanceCollection getSharingInstances(UUID consortiumId, UUID instanceId, String sourceTenantId,
String targetTenantId, Status status, Integer offset, Integer limit) {
log.debug("getSharingInstances:: parameters consortiumId: {}, instanceIdentifier: {}, sourceTenantId: {}, targetTenantId: {}, status: {}.",
consortiumId, instanceIdentifier, sourceTenantId, targetTenantId, status);
log.debug("getSharingInstances:: parameters consortiumId: {}, instanceId: {}, sourceTenantId: {}, targetTenantId: {}, status: {}.",
consortiumId, instanceId, sourceTenantId, targetTenantId, status);
consortiumService.checkConsortiumExistsOrThrow(consortiumId);
var specification = constructSpecification(instanceIdentifier, sourceTenantId, targetTenantId, status);
var specification = constructSpecification(instanceId, sourceTenantId, targetTenantId, status);

var sharingInstancePage = sharingInstanceRepository.findAll(specification, PageRequest.of(offset, limit));
var result = new SharingInstanceCollection();
Expand All @@ -144,12 +144,12 @@ public void completePromotingLocalInstance(String eventPayload) {
return;
}

var specification = constructSpecification(promotingEvent.getInstanceIdentifier(), sourceTenantId, targetTenantId, null);
var specification = constructSpecification(promotingEvent.getInstanceId(), sourceTenantId, targetTenantId, null);
var optionalSharingInstance = sharingInstanceRepository.findOne(specification);

if (optionalSharingInstance.isEmpty()) {
log.warn("completePromotingLocalInstance:: sharingInstance with instanceIdentifier: {}, sourceTenantId: {}, targetTenantId: {} does not exist",
promotingEvent.getInstanceIdentifier(), sourceTenantId, targetTenantId);
log.warn("completePromotingLocalInstance:: sharingInstance with instanceId: {}, sourceTenantId: {}, targetTenantId: {} does not exist",
promotingEvent.getInstanceId(), sourceTenantId, targetTenantId);
return;
}

Expand All @@ -162,7 +162,7 @@ public void completePromotingLocalInstance(String eventPayload) {
}

sharingInstanceRepository.save(promotedSharingInstance);
log.info("completePromotingLocalInstance:: status of sharingInstance with instanceIdentifier: {}, sourceTenantId: {}, targetTenantId: {} " +
log.info("completePromotingLocalInstance:: status of sharingInstance with instanceId: {}, sourceTenantId: {}, targetTenantId: {} " +
"has been updated to: {}", promotedSharingInstance.getInstanceId(), sourceTenantId, targetTenantId, promotedSharingInstance.getStatus());
} catch (Exception e) {
log.error("completePromotingLocalInstance:: exception occurred while promoting local sharing instance", e);
Expand All @@ -185,7 +185,7 @@ private void checkTenantsExistAndContainCentralTenantOrThrow(String sourceTenant
private SharingInstanceEntity toEntity(SharingInstance dto) {
SharingInstanceEntity entity = new SharingInstanceEntity();
entity.setId(UUID.randomUUID());
entity.setInstanceId(dto.getInstanceIdentifier());
entity.setInstanceId(dto.getInstanceId());
entity.setSourceTenantId(dto.getSourceTenantId());
entity.setTargetTenantId(dto.getTargetTenantId());
entity.setStatus(dto.getStatus());
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/swagger.api/schemas/sharingInstance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SharingInstance:
id:
type: string
format: uuid
instanceIdentifier:
instanceId:
type: string
format: uuid
sourceTenantId:
Expand All @@ -22,7 +22,7 @@ SharingInstance:
$ref: "common.yaml#/Metadata"
additionalProperties: false
required:
- instanceIdentifier
- instanceId
- sourceTenantId
- targetTenantId

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/swagger.api/sharing_instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ paths:
operationId: getSharingInstances
parameters:
- $ref: "#/components/parameters/consortiumId"
- $ref: "#/components/parameters/instanceIdentifier"
- $ref: "#/components/parameters/instanceId"
- $ref: "#/components/parameters/sourceTenantId"
- $ref: "#/components/parameters/targetTenantId"
- $ref: "#/components/parameters/status"
Expand Down Expand Up @@ -138,9 +138,9 @@ components:
$ref: "schemas/common.yaml#/uuid"
required: true
description: The ID of sharing instance
instanceIdentifier:
instanceId:
in: query
name: instanceIdentifier
name: instanceId
schema:
$ref: "schemas/common.yaml#/uuid"
description: The UUID of the instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void postAndVerifyResponseBody(String[][] instances) {

// create payload
String body = new JSONObject()
.appendField("instanceIdentifier", fields[0])
.appendField("instanceId", fields[0])
.appendField("sourceTenantId", fields[1])
.appendField("targetTenantId", fields[2])
.appendField("status", fields[3])
Expand All @@ -112,7 +112,7 @@ private void postAndVerifyResponseBody(String[][] instances) {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").isNotEmpty())
.andExpect(jsonPath("$.instanceIdentifier").value(fields[0]))
.andExpect(jsonPath("$.instanceId").value(fields[0]))
.andExpect(jsonPath("$.sourceTenantId").value(fields[1]))
.andExpect(jsonPath("$.targetTenantId").value(fields[2]))
.andExpect(jsonPath("$.status").value(fields[3]));
Expand All @@ -121,7 +121,7 @@ private void postAndVerifyResponseBody(String[][] instances) {

private String params(String instanceId, String sourceTenantId, String targetTenantId, String status) {
Map<String, String> parameters = new HashMap<>();
parameters.put("instanceIdentifier", instanceId);
parameters.put("instanceId", instanceId);
parameters.put("sourceTenantId", sourceTenantId);
parameters.put("targetTenantId", targetTenantId);
parameters.put("status", status);
Expand All @@ -131,7 +131,7 @@ private String params(String instanceId, String sourceTenantId, String targetTen
.map(k -> k + "=" + parameters.get(k))
.collect(Collectors.joining("&"));

return query.length() == 0 ? "" : "?" + query;
return query.isEmpty() ? "" : "?" + query;
}

private static class ParameterArgumentsProvider implements ArgumentsProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void shouldGetSharingInstanceByActionId() throws Exception {

@ParameterizedTest
@ValueSource(strings = {
"{\"instanceIdentifier\":\"111841e3-e6fb-4191-8fd8-5674a5107c33\",\"sourceTenantId\":\"college\", \"targetTenantId\":\"mobius\"}"
"{\"instanceId\":\"111841e3-e6fb-4191-8fd8-5674a5107c33\",\"sourceTenantId\":\"college\", \"targetTenantId\":\"mobius\"}"
})
void shouldSaveSharingInstance(String body) throws Exception {
SharingInstance sharingInstance = createSharingInstance(INSTANCE_ID, "college", "mobius");
Expand All @@ -80,7 +80,7 @@ void shouldSaveSharingInstance(String body) throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.instanceIdentifier").value(String.valueOf(INSTANCE_ID)))
.andExpect(jsonPath("$.instanceId").value(String.valueOf(INSTANCE_ID)))
.andExpect(jsonPath("$.sourceTenantId").value("college"))
.andExpect(jsonPath("$.targetTenantId").value("mobius"));
}
Expand Down
Loading