-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODEXPW-493 - Outdated preview of matched records in case of remove (…
…add) affiliation and upload the same file with Holdings, Items identifiers in Central tenant (#585) * MODEXPW-493 - get permitted and affiliated tenants * MODEXPW-493 - updates tests * MODEXPW-493 - updates tests * MODEXPW-493 - testGetAffiliatedTenants * MODEXPW-493 - update not match found logic for holdings * MODEXPW-493 - update error service logs * MODEXPW-493 - update tests * MODEXPW-493 - fix sonar * MODEXPW-493 - update tests * MODEXPW-493 - update tests * MODEXPW-493 - update tests * MODEXPW-493 - update tests * MODEXPW-493 - consortia bean * MODEXPW-493 - not found match for item * MODEXPW-493 - remove exception * MODEXPW-493 - catch feign exception * MODEXPW-493 - update module descriptor * MODEXPW-493 - add unsupported exception
- Loading branch information
Showing
16 changed files
with
399 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/java/org/folio/dew/batch/bulkedit/jobs/TenantResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.folio.dew.batch.bulkedit.jobs; | ||
|
||
import static java.lang.String.format; | ||
import static org.folio.dew.utils.BulkEditProcessorHelper.resolveIdentifier; | ||
import static org.folio.dew.utils.Constants.FILE_NAME; | ||
import static org.folio.dew.utils.Constants.NO_HOLDING_AFFILIATION; | ||
import static org.folio.dew.utils.Constants.NO_HOLDING_VIEW_PERMISSIONS; | ||
import static org.folio.dew.utils.Constants.NO_ITEM_AFFILIATION; | ||
import static org.folio.dew.utils.Constants.NO_ITEM_VIEW_PERMISSIONS; | ||
|
||
import feign.FeignException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.io.FilenameUtils; | ||
import org.folio.dew.batch.bulkedit.jobs.permissions.check.PermissionsValidator; | ||
import org.folio.dew.client.UserClient; | ||
import org.folio.dew.domain.dto.EntityType; | ||
import org.folio.dew.domain.dto.ItemIdentifier; | ||
import org.folio.dew.domain.dto.JobParameterNames; | ||
import org.folio.dew.error.BulkEditException; | ||
import org.folio.dew.service.BulkEditProcessingErrorsService; | ||
import org.folio.dew.service.ConsortiaService; | ||
import org.folio.spring.FolioExecutionContext; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class TenantResolver { | ||
|
||
private static final String UNSUPPORTED_ERROR_MESSAGE_FOR_AFFILIATIONS = "Unsupported entity type to get affiliation error message"; | ||
private static final String UNSUPPORTED_ERROR_MESSAGE_FOR_PERMISSIONS = "Unsupported entity type to get permissions error message"; | ||
|
||
private final FolioExecutionContext folioExecutionContext; | ||
private final ConsortiaService consortiaService; | ||
private final PermissionsValidator permissionsValidator; | ||
private final BulkEditProcessingErrorsService bulkEditProcessingErrorsService; | ||
private final UserClient userClient; | ||
|
||
public Set<String> getAffiliatedPermittedTenantIds(EntityType entityType, JobExecution jobExecution, String identifierType, Set<String> tenantIds, ItemIdentifier itemIdentifier) { | ||
var affiliatedTenants = consortiaService.getAffiliatedTenants(folioExecutionContext.getTenantId(), folioExecutionContext.getUserId().toString()); | ||
var jobId = jobExecution.getJobParameters().getString(JobParameterNames.JOB_ID); | ||
var fileName = FilenameUtils.getName(jobExecution.getJobParameters().getString(FILE_NAME)); | ||
var affiliatedAndPermittedTenants = new HashSet<String>(); | ||
for (var tenantId : tenantIds) { | ||
if (!affiliatedTenants.contains(tenantId)) { | ||
var user = userClient.getUserById(folioExecutionContext.getUserId().toString()); | ||
var errorMessage = format(getAffiliationErrorPlaceholder(entityType), user.getUsername(), | ||
resolveIdentifier(identifierType), itemIdentifier.getItemId(), tenantId); | ||
bulkEditProcessingErrorsService.saveErrorInCSV(jobId, itemIdentifier.getItemId(), errorMessage, fileName); | ||
} else if (!isBulkEditReadPermissionExists(tenantId, entityType)) { | ||
var user = userClient.getUserById(folioExecutionContext.getUserId().toString()); | ||
var errorMessage = format(getViewPermissionErrorPlaceholder(entityType), user.getUsername(), | ||
resolveIdentifier(identifierType), itemIdentifier.getItemId(), tenantId); | ||
bulkEditProcessingErrorsService.saveErrorInCSV(jobId, itemIdentifier.getItemId(), errorMessage, fileName); | ||
} else { | ||
affiliatedAndPermittedTenants.add(tenantId); | ||
} | ||
} | ||
return affiliatedAndPermittedTenants; | ||
} | ||
|
||
private boolean isBulkEditReadPermissionExists(String tenantId, EntityType entityType) { | ||
try { | ||
return permissionsValidator.isBulkEditReadPermissionExists(tenantId, entityType); | ||
} catch (FeignException e) { | ||
throw new BulkEditException(e.getMessage()); | ||
} | ||
} | ||
|
||
protected String getAffiliationErrorPlaceholder(EntityType entityType) { | ||
return switch (entityType) { | ||
case ITEM -> NO_ITEM_AFFILIATION; | ||
case HOLDINGS_RECORD -> NO_HOLDING_AFFILIATION; | ||
default -> throw new UnsupportedOperationException(UNSUPPORTED_ERROR_MESSAGE_FOR_AFFILIATIONS); | ||
}; | ||
} | ||
|
||
protected String getViewPermissionErrorPlaceholder(EntityType entityType) { | ||
return switch (entityType) { | ||
case ITEM -> NO_ITEM_VIEW_PERMISSIONS; | ||
case HOLDINGS_RECORD -> NO_HOLDING_VIEW_PERMISSIONS; | ||
default -> throw new UnsupportedOperationException(UNSUPPORTED_ERROR_MESSAGE_FOR_PERMISSIONS); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.folio.dew.client; | ||
|
||
import org.folio.dew.domain.bean.ConsortiaCollection; | ||
import org.folio.dew.domain.dto.UserTenantCollection; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@FeignClient(name = "consortia") | ||
public interface ConsortiumClient { | ||
|
||
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) | ||
ConsortiaCollection getConsortia(); | ||
|
||
@GetMapping(value = "/{consortiumId}/user-tenants", produces = MediaType.APPLICATION_JSON_VALUE) | ||
UserTenantCollection getConsortiaUserTenants(@PathVariable String consortiumId, @RequestParam String userId, @RequestParam int limit); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.folio.dew.domain.bean; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Consortia { | ||
|
||
private String id; | ||
} |
Oops, something went wrong.