Skip to content

Commit

Permalink
MODBULKOPS-329 - Include tenantId in Item's and Holdings' Notes names…
Browse files Browse the repository at this point in the history
… in ECS (#260)

* MODBULKOPS-329 Added tenant
  • Loading branch information
obozhko-folio authored Sep 11, 2024
1 parent 1027374 commit 4a14630
Show file tree
Hide file tree
Showing 26 changed files with 322 additions and 63 deletions.
14 changes: 13 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@
"pathPattern": "/bulk-operations/{operationId}/cancel",
"permissionsRequired": ["bulk-operations.item.cancel.post"],
"modulePermissions": [ ]
},
{
"methods": [ "GET" ],
"pathPattern": "/bulk-operations/used-tenants/{operationId}",
"permissionsRequired": ["bulk-operations.used.tenants.get"],
"modulePermissions": [ ]
}
]
},
Expand Down Expand Up @@ -365,6 +371,11 @@
"displayName" : "cancel operation by id",
"description" : "Cancel operation by id"
},
{
"permissionName": "bulk-operations.used.tenants.get",
"displayName" : "get used tenants by operation id",
"description" : "Get used tenants by operation id"
},
{
"permissionName" : "bulk-operations.all",
"displayName" : "bulk-operations all",
Expand All @@ -384,7 +395,8 @@
"bulk-operations.list-users.collection.get",
"bulk-operations.files.item.delete",
"bulk-operations.item.cancel.post",
"bulk-operations.item.query.post"
"bulk-operations.item.query.post",
"bulk-operations.used.tenants.get"
]
}
],
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/folio/bulkops/client/SearchConsortium.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.folio.bulkops.client;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import java.util.UUID;

import org.folio.bulkops.domain.bean.ConsortiumHoldingCollection;
import org.folio.bulkops.domain.bean.ConsortiumItemCollection;
import org.folio.bulkops.domain.bean.UploadIdentifiers;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "search/consortium")
public interface SearchConsortium {

@GetMapping(value="/holdings", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
ConsortiumHoldingCollection getHoldingsById(@RequestParam UUID instanceId);

@PostMapping(value="/batch/holdings", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
ConsortiumHoldingCollection getHoldingsByIdentifiers(@RequestBody UploadIdentifiers uploadIdentifiers);

@PostMapping(value="/batch/items", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
ConsortiumItemCollection getItemsByIdentifiers(@RequestBody UploadIdentifiers uploadIdentifiers);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -214,6 +215,12 @@ public ResponseEntity<Void> cancelOperationById(UUID operationId) {
return new ResponseEntity<>(HttpStatus.OK);
}

@Override
public ResponseEntity<List<String>> getListUsedTenants(UUID operationId) {
var bulkOperation = bulkOperationService.getOperationById(operationId);
return new ResponseEntity<>(bulkOperation.getUsedTenants(), HttpStatus.OK);
}

@Override
public ResponseEntity<BulkOperationDto> triggerBulkEditByQuery(UUID xOkapiUserId, QueryRequest queryRequest) {
return new ResponseEntity<>(bulkOperationMapper.mapToDto(bulkOperationService.triggerByQuery(xOkapiUserId, queryRequest)), HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ default String getTenant() {
return StringUtils.EMPTY;
}
@JsonIgnore
default void setTenantToNotes(){
default void setTenantToNotes() {
}
@JsonIgnore
default void setTenant(String tenantId) {
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/folio/bulkops/domain/bean/ConsortiumItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.folio.bulkops.domain.bean;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConsortiumItem {
private String id;
private String tenantId;
private String instanceId;
private String holdingsRecordId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.folio.bulkops.domain.bean;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConsortiumItemCollection {

@JsonProperty("items")
private List<ConsortiumItem> items = new ArrayList<>();
}
13 changes: 13 additions & 0 deletions src/main/java/org/folio/bulkops/domain/bean/HoldingsRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public class HoldingsRecord implements BulkOperationsEntity {
@JsonProperty("itemBarcode")
private String itemBarcode;

@JsonProperty("tenantId")
private String tenantId;

@Override
public String getIdentifier(IdentifierType identifierType) {
return switch (identifierType) {
Expand All @@ -271,4 +274,14 @@ public Integer _version() {
public Boolean getDiscoverySuppress() {
return isNull(discoverySuppress) ? FALSE : discoverySuppress;
}

@Override
public void setTenantToNotes() {
getNotes().forEach(note -> note.setTenantId(tenantId));
}

@Override
public void setTenant(String tenantId) {
this.tenantId = tenantId;
}
}
13 changes: 13 additions & 0 deletions src/main/java/org/folio/bulkops/domain/bean/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ public class Item implements BulkOperationsEntity, ElectronicAccessEntity {
@Valid
private List<CirculationNote> circulationNotes;

@JsonProperty("tenantId")
private String tenantId;

@Override
public String getIdentifier(IdentifierType identifierType) {
return switch (identifierType) {
Expand All @@ -347,4 +350,14 @@ public Integer _version() {
public Boolean getDiscoverySuppress() {
return isNull(discoverySuppress) ? FALSE : discoverySuppress;
}

@Override
public void setTenantToNotes() {
getNotes().forEach(note -> note.setTenantId(tenantId));
}

@Override
public void setTenant(String tenantId) {
this.tenantId = tenantId;
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/folio/bulkops/domain/bean/UploadIdentifiers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.folio.bulkops.domain.bean;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import lombok.Builder;

import java.util.List;
import java.util.UUID;

@Data
@With
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class UploadIdentifiers {

@JsonProperty("identifierType")
private String identifierType;

@JsonProperty("identifierValues")
private List<UUID> identifierValues;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import org.folio.bulkops.service.HoldingsReferenceHelper;

public class HoldingsNoteListConverter extends BaseConverter<List<HoldingsNote>> {
private static final int NUMBER_OF_HOLDINGS_NOTE_ELEMENTS = 3;
private static final int NUMBER_OF_HOLDINGS_NOTE_ELEMENTS = 5;
private static final int HOLDINGS_NOTE_NOTE_TYPE_INDEX = 0;
private static final int HOLDINGS_NOTE_NOTE_INDEX = 1;
private static final int TENANT_INDEX = 3;
private static final int HOLDINGS_NOTE_STAFF_ONLY_INDEX = 2;

@Override
Expand Down Expand Up @@ -57,6 +58,7 @@ private HoldingsNote restoreHoldingsNote(String s) {
.holdingsNoteTypeId(HoldingsReferenceHelper.service().getNoteTypeIdByName(restore(tokens[HOLDINGS_NOTE_NOTE_TYPE_INDEX])))
.note(restore(tokens[HOLDINGS_NOTE_NOTE_INDEX]))
.staffOnly(ObjectUtils.isEmpty(tokens[HOLDINGS_NOTE_STAFF_ONLY_INDEX]) ? null : Boolean.parseBoolean(tokens[HOLDINGS_NOTE_STAFF_ONLY_INDEX]))
.tenantId(tokens[TENANT_INDEX])
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import org.folio.bulkops.service.ItemReferenceHelper;

public class ItemNoteListConverter extends BaseConverter<List<ItemNote>> {
private static final int NUMBER_OF_ITEM_NOTE_COMPONENTS = 3;
private static final int NUMBER_OF_ITEM_NOTE_COMPONENTS = 5;
private static final int NOTE_TYPE_NAME_INDEX = 0;
private static final int NOTE_INDEX = 1;
private static final int STAFF_ONLY_OFFSET = 1;
private static final int TENANT_INDEX = 3;
private static final int STAFF_ONLY_OFFSET = 3;

@Override
public List<ItemNote> convertToObject(String value) {
Expand All @@ -36,9 +37,11 @@ public String convertToString(List<ItemNote> object) {
return object.stream()
.filter(Objects::nonNull)
.map(itemNote -> String.join(ARRAY_DELIMITER,
escape(ItemReferenceHelper.service().getNoteTypeNameById(itemNote.getItemNoteTypeId())),
escape(ItemReferenceHelper.service().getNoteTypeNameById(itemNote.getItemNoteTypeId(), itemNote.getTenantId())),
escape(itemNote.getNote()),
escape(booleanToStringNullSafe(itemNote.getStaffOnly()))))
escape(booleanToStringNullSafe(itemNote.getStaffOnly())),
itemNote.getTenantId(),
itemNote.getItemNoteTypeId()))
.collect(Collectors.joining(ITEM_DELIMITER));
}

Expand All @@ -55,6 +58,7 @@ private ItemNote restoreItemNote(String s) {
.map(SpecialCharacterEscaper::restore)
.collect(Collectors.joining(";")))
.staffOnly(Boolean.valueOf(tokens[tokens.length - STAFF_ONLY_OFFSET]))
.tenantId(tokens[TENANT_INDEX])
.build();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.folio.bulkops.client.HoldingsClient;
import org.folio.bulkops.client.InstanceClient;
import org.folio.bulkops.client.ItemClient;
import org.folio.bulkops.client.SearchConsortiumHoldings;
import org.folio.bulkops.client.SearchConsortium;
import org.folio.bulkops.client.UserClient;
import org.folio.bulkops.domain.bean.ConsortiumHolding;
import org.folio.bulkops.domain.bean.ExtendedInstance;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class InstanceUpdateProcessor extends AbstractUpdateProcessor<ExtendedIns
private final RuleService ruleService;
private final HoldingsClient holdingsClient;
private final ItemClient itemClient;
private final SearchConsortiumHoldings searchConsortiumHoldings;
private final SearchConsortium searchConsortium;
private final ErrorService errorService;
private final HoldingsReferenceService holdingsReferenceService;
private final ConsortiaService consortiaService;
Expand Down Expand Up @@ -94,7 +94,7 @@ private boolean applyRuleToAssociatedRecords(ExtendedInstance extendedInstance,
itemsUpdated = suppressItemsIfRequired(holdings, shouldApplyToItems, instance.getDiscoverySuppress());
} else {
var instance = extendedInstance.getEntity();
var consortiumHoldings = searchConsortiumHoldings.getHoldingsById(UUID.fromString(instance.getId())).getHoldings();
var consortiumHoldings = searchConsortium.getHoldingsById(UUID.fromString(instance.getId())).getHoldings();
Map<String, List<String>> consortiaHoldingsIdsPerTenant = consortiumHoldings.stream()
.filter(h -> !folioExecutionContext.getTenantId().equals(h.getTenantId()))
.collect(Collectors.groupingBy(ConsortiumHolding::getTenantId, Collectors.mapping(ConsortiumHolding::getId, Collectors.toList())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.opencsv.CSVReaderBuilder;
import com.opencsv.RFC4180ParserBuilder;
import lombok.extern.log4j.Log4j2;
import org.folio.bulkops.domain.dto.EntityType;
import org.folio.bulkops.domain.entity.BulkOperation;
import org.folio.bulkops.service.NoteTableUpdater;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -72,7 +73,9 @@ public byte[] processNotes(byte[] input, BulkOperation bulkOperation) {
protected abstract int getNotePosition();

private String[] processNotesData(String[] line, List<String> noteTypeNames, BulkOperation bulkOperation) {
return noteTableUpdater.enrichWithNotesByType(new ArrayList<>(Arrays.asList(line)), getNotePosition(), noteTypeNames, bulkOperation.getTenantNotePairs()).stream()
return noteTableUpdater.enrichWithNotesByType(new ArrayList<>(Arrays.asList(line)), getNotePosition(), noteTypeNames,
bulkOperation.getTenantNotePairs(), bulkOperation.getEntityType() == EntityType.INSTANCE ||
bulkOperation.getEntityType() == EntityType.INSTANCE_MARC).stream()
.map(this::processSpecialCharacters)
.toArray(String[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ public void commit(BulkOperation operation) {
} else {
var tenantIdOfEntity = result.getTenant();
try (var ignored = new FolioExecutionContextSetter(prepareContextForTenant(tenantIdOfEntity, folioModuleMetadata, folioExecutionContext))) {
result.getRecordBulkOperationEntity().setTenant(tenantIdOfEntity);
result.getRecordBulkOperationEntity().setTenantToNotes();
writeBeanToCsv(operation, csvWriter, result.getRecordBulkOperationEntity(), bulkOperationExecutionContents);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public DamagedStatus getDamagedStatusByName(String name) {
return itemReferenceService.getDamagedStatusByName(name);
}

public String getNoteTypeNameById(String noteTypeId) {
return itemReferenceService.getNoteTypeNameById(noteTypeId);
public String getNoteTypeNameById(String noteTypeId, String tenantId) {
return itemReferenceService.getNoteTypeNameById(noteTypeId, tenantId);
}

public String getNoteTypeIdByName(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public DamagedStatus getDamagedStatusByName(String name) {
}

@Cacheable(cacheNames = "noteTypeNames")
public String getNoteTypeNameById(String noteTypeId) {
public String getNoteTypeNameById(String noteTypeId, String tenantId) {
try {
return isEmpty(noteTypeId) ? EMPTY : itemNoteTypeClient.getNoteTypeById(noteTypeId).getName();
} catch (Exception e) {
Expand Down
Loading

0 comments on commit 4a14630

Please sign in to comment.