chore: Split changes for overridden package import (#31712)

This commit is contained in:
Nidhi 2024-03-13 10:34:44 +05:30 committed by GitHub
parent f65d9d0ead
commit 658ea94ae6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 47 deletions

View File

@ -75,7 +75,7 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
ImportingMetaDTO importingMetaDTO,
MappedImportableResourcesDTO mappedImportableResourcesDTO) {
ArtifactBasedImportableService<ActionCollection, ?> artifactBasedExportableService =
ArtifactBasedImportableService<ActionCollection, ?> artifactBasedImportableService =
getArtifactBasedImportableService(importingMetaDTO);
Mono<List<ActionCollection>> importedActionCollectionMono = Mono.just(importedActionCollectionList);
@ -83,14 +83,14 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
if (importingMetaDTO.getAppendToArtifact()) {
importedActionCollectionMono = importedActionCollectionMono.map(importedActionCollections -> {
List<String> importedContextNames =
artifactBasedExportableService.getImportedContextNames(mappedImportableResourcesDTO);
artifactBasedImportableService.getImportedContextNames(mappedImportableResourcesDTO);
Map<String, String> newToOldNameMap = mappedImportableResourcesDTO.getContextNewNameToOldName();
for (String newContextName : importedContextNames) {
String oldContextName = newToOldNameMap.get(newContextName);
if (!newContextName.equals(oldContextName)) {
artifactBasedExportableService.renameContextInImportableResources(
artifactBasedImportableService.renameContextInImportableResources(
importedActionCollections, oldContextName, newContextName);
}
}
@ -125,7 +125,7 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
ImportingMetaDTO importingMetaDTO,
MappedImportableResourcesDTO mappedImportableResourcesDTO) {
ArtifactBasedImportableService<ActionCollection, ?> artifactBasedExportableService =
ArtifactBasedImportableService<ActionCollection, ?> artifactBasedImportableService =
getArtifactBasedImportableService(importingMetaDTO);
/* Mono.just(importableArtifact) is created to avoid the eagerly fetching of existing actionCollections
@ -138,7 +138,7 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
// Map of gitSyncId to actionCollection of the existing records in DB
Mono<Map<String, ActionCollection>> actionCollectionsInCurrentArtifactMono =
artifactBasedExportableService
artifactBasedImportableService
.getExistingResourcesInCurrentArtifactFlux(artifact)
.filter(collection -> collection.getGitSyncId() != null)
.collectMap(ActionCollection::getGitSyncId);
@ -147,7 +147,7 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
if (artifact.getGitArtifactMetadata() != null) {
final String defaultArtifactId =
artifact.getGitArtifactMetadata().getDefaultArtifactId();
actionCollectionsInBranchesMono = artifactBasedExportableService
actionCollectionsInBranchesMono = artifactBasedImportableService
.getExistingResourcesInOtherBranchesFlux(defaultArtifactId, artifact.getId())
.filter(actionCollection -> actionCollection.getGitSyncId() != null)
.collectMap(ActionCollection::getGitSyncId);
@ -190,10 +190,11 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
if (actionsCollectionsInBranches.containsKey(actionCollection.getGitSyncId())) {
branchedActionCollection =
getExistingCollectionInOtherBranchesForImportedCollection(
mappedImportableResourcesDTO,
actionsCollectionsInBranches,
actionCollection);
artifactBasedImportableService
.getExistingEntityInOtherBranchForImportedEntity(
mappedImportableResourcesDTO,
actionsCollectionsInBranches,
actionCollection);
}
Context defaultContext = populateIdReferencesAndReturnDefaultContext(
@ -209,10 +210,11 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
// Since the resource is already present in DB, just update resource
ActionCollection existingActionCollection =
getExistingCollectionInCurrentBranchForImportedCollection(
mappedImportableResourcesDTO,
actionsCollectionsInCurrentArtifact,
actionCollection);
artifactBasedImportableService
.getExistingEntityInCurrentBranchForImportedEntity(
mappedImportableResourcesDTO,
actionsCollectionsInCurrentArtifact,
actionCollection);
updateExistingCollection(
importingMetaDTO,
@ -226,7 +228,7 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
.getSavedActionCollectionMap()
.put(idFromJsonFile, existingActionCollection);
} else {
artifactBasedExportableService.createNewResource(
artifactBasedImportableService.createNewResource(
importingMetaDTO, actionCollection, defaultContext);
populateDomainMappedReferences(mappedImportableResourcesDTO, actionCollection);
@ -374,13 +376,6 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
return actionsCollectionsInCurrentArtifact.get(actionCollection.getGitSyncId());
}
protected ActionCollection getExistingCollectionInOtherBranchesForImportedCollection(
MappedImportableResourcesDTO mappedImportableResourcesDTO,
Map<String, ActionCollection> actionsCollectionsInOtherArtifact,
ActionCollection actionCollection) {
return actionsCollectionsInOtherArtifact.get(actionCollection.getGitSyncId());
}
protected boolean existingArtifactContainsCollection(
Map<String, ActionCollection> actionsCollectionsInCurrentArtifact, ActionCollection actionCollection) {
return actionCollection.getGitSyncId() != null

View File

@ -30,4 +30,16 @@ public interface ArtifactBasedImportableServiceCE<T extends BaseDomain, U extend
T resource);
void createNewResource(ImportingMetaDTO importingMetaDTO, T actionCollection, Context defaultContext);
default T getExistingEntityInCurrentBranchForImportedEntity(
MappedImportableResourcesDTO mappedImportableResourcesDTO,
Map<String, T> entityInCurrentArtifact,
T entity) {
return entityInCurrentArtifact.get(entity.getGitSyncId());
}
default T getExistingEntityInOtherBranchForImportedEntity(
MappedImportableResourcesDTO mappedImportableResourcesDTO, Map<String, T> entityInOtherArtifact, T entity) {
return entityInOtherArtifact.get(entity.getGitSyncId());
}
}

View File

@ -202,7 +202,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
ImportingMetaDTO importingMetaDTO,
MappedImportableResourcesDTO mappedImportableResourcesDTO) {
ArtifactBasedImportableService<NewAction, ?> artifactBasedExportableService =
ArtifactBasedImportableService<NewAction, ?> artifactBasedImportableService =
getArtifactBasedImportableService(importingMetaDTO);
Mono<List<NewAction>> importedNewActionMono = Mono.justOrEmpty(importedNewActions);
@ -210,14 +210,14 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
if (TRUE.equals(importingMetaDTO.getAppendToArtifact())) {
importedNewActionMono = importedNewActionMono.map(importedNewActionList -> {
List<String> importedContextNames =
artifactBasedExportableService.getImportedContextNames(mappedImportableResourcesDTO);
artifactBasedImportableService.getImportedContextNames(mappedImportableResourcesDTO);
Map<String, String> newToOldNameMap = mappedImportableResourcesDTO.getContextNewNameToOldName();
for (String newContextName : importedContextNames) {
String oldContextName = newToOldNameMap.get(newContextName);
if (!newContextName.equals(oldContextName)) {
artifactBasedExportableService.renameContextInImportableResources(
artifactBasedImportableService.renameContextInImportableResources(
importedNewActionList, oldContextName, newContextName);
}
}
@ -248,7 +248,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
ImportingMetaDTO importingMetaDTO,
MappedImportableResourcesDTO mappedImportableResourcesDTO) {
ArtifactBasedImportableService<NewAction, ?> artifactBasedExportableService =
ArtifactBasedImportableService<NewAction, ?> artifactBasedImportableService =
getArtifactBasedImportableService(importingMetaDTO);
/* Mono.just(importableArtifact) is created to avoid the eagerly fetching of existing actions
@ -258,7 +258,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
ImportActionResultDTO importActionResultDTO = new ImportActionResultDTO();
mappedImportableResourcesDTO.setActionResultDTO(importActionResultDTO);
Mono<Map<String, NewAction>> actionsInCurrentArtifactMono = artifactBasedExportableService
Mono<Map<String, NewAction>> actionsInCurrentArtifactMono = artifactBasedImportableService
.getExistingResourcesInCurrentArtifactFlux(artifact)
.filter(collection -> collection.getGitSyncId() != null)
.collectMap(NewAction::getGitSyncId);
@ -268,7 +268,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
if (artifact.getGitArtifactMetadata() != null) {
final String defaultArtifactId =
artifact.getGitArtifactMetadata().getDefaultArtifactId();
actionsInOtherBranchesMono = artifactBasedExportableService
actionsInOtherBranchesMono = artifactBasedImportableService
.getExistingResourcesInOtherBranchesFlux(defaultArtifactId, artifact.getId())
.filter(newAction -> newAction.getGitSyncId() != null)
.collectMap(NewAction::getGitSyncId);
@ -305,8 +305,9 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
NewAction branchedNewAction = null;
if (actionsInBranches.containsKey(newAction.getGitSyncId())) {
branchedNewAction = getExistingActionInOtherBranchForImportedAction(
mappedImportableResourcesDTO, actionsInBranches, newAction);
branchedNewAction =
artifactBasedImportableService.getExistingEntityInOtherBranchForImportedEntity(
mappedImportableResourcesDTO, actionsInBranches, newAction);
}
Context defaultContext = populateIdReferencesAndReturnDefaultContext(
@ -320,8 +321,12 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
if (existingArtifactContainsAction(actionsInCurrentArtifact, newAction)) {
// Since the resource is already present in DB, just update resource
NewAction existingAction = getExistingActionInCurrentBranchForImportedAction(
mappedImportableResourcesDTO, actionsInCurrentArtifact, newAction);
NewAction existingAction =
artifactBasedImportableService
.getExistingEntityInCurrentBranchForImportedEntity(
mappedImportableResourcesDTO,
actionsInCurrentArtifact,
newAction);
updateExistingAction(
existingAction,
@ -335,7 +340,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
putActionIdInMap(existingAction, importActionResultDTO);
} else {
artifactBasedExportableService.createNewResource(
artifactBasedImportableService.createNewResource(
importingMetaDTO, newAction, defaultContext);
populateDomainMappedReferences(mappedImportableResourcesDTO, newAction);
@ -452,20 +457,6 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
}
}
protected NewAction getExistingActionInCurrentBranchForImportedAction(
MappedImportableResourcesDTO mappedImportableResourcesDTO,
Map<String, NewAction> actionsInCurrentArtifact,
NewAction newAction) {
return actionsInCurrentArtifact.get(newAction.getGitSyncId());
}
protected NewAction getExistingActionInOtherBranchForImportedAction(
MappedImportableResourcesDTO mappedImportableResourcesDTO,
Map<String, NewAction> actionsInOtherArtifact,
NewAction newAction) {
return actionsInOtherArtifact.get(newAction.getGitSyncId());
}
protected boolean existingArtifactContainsAction(
Map<String, NewAction> actionsInCurrentArtifact, NewAction newAction) {
return newAction.getGitSyncId() != null && actionsInCurrentArtifact.containsKey(newAction.getGitSyncId());