Skip to content

Commit

Permalink
[PAGOPA-2382] fix: Update with upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang committed Nov 18, 2024
1 parent 014b381 commit 114d883
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.gpd.upload.entity.Status;
import it.gov.pagopa.gpd.upload.model.AppInfo;
import it.gov.pagopa.gpd.upload.model.ProblemJson;
Expand All @@ -23,6 +24,7 @@
import jakarta.inject.Inject;
import jakarta.validation.constraints.NotBlank;

@Tag(name = "Support API")
@ExecuteOn(TaskExecutors.IO)
@Controller("support")
public class SupportController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public Status saveStatus(Status status) {
}
}

public Status upsert(Status status) {
try {
CosmosItemResponse<Status> response = container.upsertItem(status);
return response.getItem();
} catch (CosmosException ex) {
log.error("[Error][StatusRepository@saveStatus] The Status upsert was not successful: {}", ex.getStatusCode());
if(ex.getStatusCode() == HttpStatus.CONFLICT.getCode())
return findStatusById(status.getId(), status.fiscalCode); // already exists, created by blob-consumer function
if(ex.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR.getCode())
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.name(), "Status upsert unavailable");
else
throw new AppException(HttpStatus.valueOf(ex.getStatusCode()), String.valueOf(ex.getStatusCode()), "Status upsert failed");
}
}

public Status findStatusById(String id, String fiscalCode) {
try {
CosmosItemResponse<Status> response = container.readItem(id, new PartitionKey(fiscalCode), Status.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public Status recover(String brokerId, String organizationFiscalCode, String upl
.statusCode(HttpStatus.CREATED.getCode())
.statusMessage(statusService.getDetail(HttpStatus.CREATED))
.build());
statusService.save(current);

return current;
return statusService.upsert(current);
}

private List<String> getAlreadyCreatedIUPD(String organizationFiscalCode, List<String> inputIUPD, List<String> processedIUPD) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void createUploadStatus(String organizationFiscalCode, String brokerId, S
statusRepository.saveStatus(status);
}

public void save(Status status) {
statusRepository.saveStatus(status);
public Status upsert(Status status) {
return statusRepository.upsert(status);
}

private UploadStatus map(Status status) {
Expand Down

0 comments on commit 114d883

Please sign in to comment.