Skip to content

Commit

Permalink
Extract unsafe statement service (!1202)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelKonrad committed Feb 7, 2025
1 parent 06a7e95 commit 72f914f
Show file tree
Hide file tree
Showing 185 changed files with 1,552 additions and 933 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import org.orkg.graph.input.LiteralUseCases
import org.orkg.graph.input.ResourceUseCases
import org.orkg.graph.input.StatementUseCases
import org.orkg.graph.input.UnsafeResourceUseCases
import org.orkg.graph.input.UnsafeStatementUseCases
import org.orkg.graph.output.ListRepository
import org.orkg.graph.output.ResourceRepository
import org.orkg.graph.output.StatementRepository
Expand All @@ -108,6 +109,7 @@ class ComparisonService(
private val resourceService: ResourceUseCases,
private val unsafeResourceUseCases: UnsafeResourceUseCases,
private val statementService: StatementUseCases,
private val unsafeStatementUseCases: UnsafeStatementUseCases,
private val literalService: LiteralUseCases,
private val listService: ListUseCases,
private val listRepository: ListRepository,
Expand Down Expand Up @@ -209,13 +211,13 @@ class ComparisonService(
SDGValidator({ it.sustainableDevelopmentGoals }),
ComparisonAuthorCreateValidator(resourceRepository, statementRepository),
ComparisonResourceCreator(unsafeResourceUseCases),
ComparisonDescriptionCreator(literalService, statementService),
ComparisonAuthorCreator(unsafeResourceUseCases, statementService, literalService, listService),
ComparisonSDGCreator(literalService, statementService),
ComparisonResearchFieldCreator(literalService, statementService),
ComparisonReferencesCreator(literalService, statementService),
ComparisonIsAnonymizedCreator(literalService, statementService),
ComparisonContributionCreator(statementService),
ComparisonDescriptionCreator(literalService, unsafeStatementUseCases),
ComparisonAuthorCreator(unsafeResourceUseCases, unsafeStatementUseCases, literalService, listService),
ComparisonSDGCreator(literalService, unsafeStatementUseCases),
ComparisonResearchFieldCreator(literalService, unsafeStatementUseCases),
ComparisonReferencesCreator(literalService, unsafeStatementUseCases),
ComparisonIsAnonymizedCreator(literalService, unsafeStatementUseCases),
ComparisonContributionCreator(unsafeStatementUseCases),
ComparisonTableCreator(comparisonTableRepository)
)
return steps.execute(command, CreateComparisonState()).comparisonId!!
Expand All @@ -233,7 +235,7 @@ class ComparisonService(
classes = setOf(Classes.comparisonRelatedResource)
)
)
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = command.contributorId,
subjectId = command.comparisonId,
Expand All @@ -242,7 +244,7 @@ class ComparisonService(
)
)
if (command.image != null) {
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = command.contributorId,
subjectId = resourceId,
Expand All @@ -257,7 +259,7 @@ class ComparisonService(
)
}
if (command.url != null) {
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = command.contributorId,
subjectId = resourceId,
Expand All @@ -272,7 +274,7 @@ class ComparisonService(
)
}
if (command.description != null) {
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = command.contributorId,
subjectId = resourceId,
Expand Down Expand Up @@ -301,7 +303,7 @@ class ComparisonService(
classes = setOf(Classes.comparisonRelatedFigure)
)
)
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = command.contributorId,
subjectId = command.comparisonId,
Expand All @@ -310,7 +312,7 @@ class ComparisonService(
)
)
if (command.image != null) {
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = command.contributorId,
subjectId = figureId,
Expand All @@ -325,7 +327,7 @@ class ComparisonService(
)
}
if (command.description != null) {
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = command.contributorId,
subjectId = figureId,
Expand Down Expand Up @@ -357,13 +359,13 @@ class ComparisonService(
SDGValidator({ it.sustainableDevelopmentGoals }),
ComparisonAuthorUpdateValidator(resourceRepository, statementRepository),
ComparisonResourceUpdater(unsafeResourceUseCases),
ComparisonDescriptionUpdater(literalService, statementService),
ComparisonResearchFieldUpdater(literalService, statementService),
ComparisonAuthorUpdater(unsafeResourceUseCases, statementService, literalService, listService, listRepository),
ComparisonSDGUpdater(literalService, statementService),
ComparisonContributionUpdater(literalService, statementService),
ComparisonReferencesUpdater(literalService, statementService),
ComparisonIsAnonymizedUpdater(literalService, statementService),
ComparisonDescriptionUpdater(literalService, statementService, unsafeStatementUseCases),
ComparisonResearchFieldUpdater(literalService, statementService, unsafeStatementUseCases),
ComparisonAuthorUpdater(unsafeResourceUseCases, statementService, unsafeStatementUseCases, literalService, listService, listRepository),
ComparisonSDGUpdater(literalService, statementService, unsafeStatementUseCases),
ComparisonContributionUpdater(literalService, statementService, unsafeStatementUseCases),
ComparisonReferencesUpdater(literalService, statementService, unsafeStatementUseCases),
ComparisonIsAnonymizedUpdater(literalService, statementService, unsafeStatementUseCases),
ComparisonTableUpdater(comparisonTableRepository)
)
steps.execute(command, UpdateComparisonState())
Expand All @@ -374,7 +376,8 @@ class ComparisonService(
comparisonService = this,
resourceService = resourceService,
literalService = literalService,
statementService = statementService
statementService = statementService,
unsafeStatementUseCases = unsafeStatementUseCases,
).execute(command)
}

Expand All @@ -383,7 +386,8 @@ class ComparisonService(
comparisonService = this,
resourceService = resourceService,
literalService = literalService,
statementService = statementService
statementService = statementService,
unsafeStatementUseCases = unsafeStatementUseCases
).execute(command)
}

Expand All @@ -408,9 +412,9 @@ class ComparisonService(
override fun publish(command: PublishComparisonCommand): ThingId {
val steps = listOf<Action<PublishComparisonCommand, PublishComparisonState>>(
ComparisonPublishableValidator(this, comparisonTableRepository),
ComparisonVersionCreator(resourceRepository, statementRepository, unsafeResourceUseCases, statementService, literalService, listService, comparisonPublishedRepository),
ComparisonVersionHistoryUpdater(statementService, unsafeResourceUseCases),
ComparisonVersionDoiPublisher(statementService, literalService, comparisonRepository, doiService, comparisonPublishBaseUri)
ComparisonVersionCreator(resourceRepository, statementRepository, unsafeResourceUseCases, unsafeStatementUseCases, literalService, listService, comparisonPublishedRepository),
ComparisonVersionHistoryUpdater(unsafeStatementUseCases, unsafeResourceUseCases),
ComparisonVersionDoiPublisher(unsafeStatementUseCases, literalService, comparisonRepository, doiService, comparisonPublishBaseUri)
)
return steps.execute(command, PublishComparisonState()).comparisonVersionId!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.orkg.graph.input.LiteralUseCases
import org.orkg.graph.input.PredicateUseCases
import org.orkg.graph.input.ResourceUseCases
import org.orkg.graph.input.StatementUseCases
import org.orkg.graph.input.UnsafeStatementUseCases
import org.orkg.graph.output.ResourceRepository
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
Expand All @@ -42,6 +43,7 @@ class LegacyPaperService(
private val literalService: LiteralUseCases,
private val predicateService: PredicateUseCases,
private val statementService: StatementUseCases,
private val unsafeStatementUseCases: UnsafeStatementUseCases,
private val contributorService: RetrieveContributorUseCase,
private val objectService: CreateObjectUseCase,
private val resourceRepository: ResourceRepository,
Expand All @@ -67,7 +69,7 @@ class LegacyPaperService(
request.paper.contributions!!.forEach {
val contributionId = addCompleteContribution(it, request, userUUID)
// Create statement between paper and contribution
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = userId,
subjectId = paperId,
Expand Down Expand Up @@ -162,7 +164,7 @@ class LegacyPaperService(
label = request.paper.doi!!
)
)
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = userId,
subjectId = paperId,
Expand All @@ -180,7 +182,7 @@ class LegacyPaperService(
label = request.paper.url!!
)
)
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = userId,
subjectId = paperId,
Expand All @@ -194,7 +196,7 @@ class LegacyPaperService(
handleAuthors(request, userId, paperId, observatoryId, organizationId)

// paper publication date
if (request.paper.hasPublicationMonth()) statementService.add(
if (request.paper.hasPublicationMonth()) unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = userId,
subjectId = paperId,
Expand All @@ -208,7 +210,7 @@ class LegacyPaperService(
)
)
)
if (request.paper.hasPublicationYear()) statementService.add(
if (request.paper.hasPublicationYear()) unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = userId,
subjectId = paperId,
Expand All @@ -229,7 +231,7 @@ class LegacyPaperService(
)

// paper research field
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = userId,
subjectId = paperId,
Expand Down Expand Up @@ -272,7 +274,7 @@ class LegacyPaperService(
resourceRepository.findById(resourceId).get()
}
// create a statement with the venue resource
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = userId,
subjectId = paperId,
Expand Down Expand Up @@ -333,7 +335,7 @@ class LegacyPaperService(
)
)
// Add ORCID id to the new resource
statementService.add(
unsafeStatementUseCases.create(
CreateStatementUseCase.CreateCommand(
contributorId = userId,
subjectId = authorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import org.orkg.graph.input.LiteralUseCases
import org.orkg.graph.input.ResourceUseCases
import org.orkg.graph.input.StatementUseCases
import org.orkg.graph.input.UnsafeResourceUseCases
import org.orkg.graph.input.UnsafeStatementUseCases
import org.orkg.graph.output.ListRepository
import org.orkg.graph.output.ResourceRepository
import org.orkg.graph.output.StatementRepository
Expand All @@ -95,6 +96,7 @@ class LiteratureListService(
private val unsafeResourceUseCases: UnsafeResourceUseCases,
private val literalService: LiteralUseCases,
private val statementService: StatementUseCases,
private val unsafeStatementUseCases: UnsafeStatementUseCases,
private val listService: ListUseCases,
private val listRepository: ListRepository,
private val contributorRepository: ContributorRepository,
Expand Down Expand Up @@ -162,10 +164,10 @@ class LiteratureListService(
ObservatoryValidator(observatoryRepository, { it.observatories }),
LiteratureListSectionsCreateValidator(resourceRepository),
LiteratureListResourceCreator(unsafeResourceUseCases),
LiteratureListResearchFieldCreator(literalService, statementService),
LiteratureListAuthorCreator(unsafeResourceUseCases, statementService, literalService, listService),
LiteratureListSDGCreator(literalService, statementService),
LiteratureListSectionsCreator(literalService, unsafeResourceUseCases, statementService)
LiteratureListResearchFieldCreator(literalService, unsafeStatementUseCases),
LiteratureListAuthorCreator(unsafeResourceUseCases, unsafeStatementUseCases, literalService, listService),
LiteratureListSDGCreator(literalService, unsafeStatementUseCases),
LiteratureListSectionsCreator(literalService, unsafeResourceUseCases, unsafeStatementUseCases)
)
return steps.execute(command, CreateLiteratureListState()).literatureListId!!
}
Expand All @@ -175,7 +177,7 @@ class LiteratureListService(
LiteratureListSectionExistenceCreateValidator(resourceRepository),
LiteratureListSectionIndexValidator(statementRepository),
LiteratureListSectionCreateValidator(resourceRepository),
LiteratureListSectionCreator(literalService, unsafeResourceUseCases, statementService)
LiteratureListSectionCreator(literalService, unsafeResourceUseCases, statementService, unsafeStatementUseCases)
)
return steps.execute(command, CreateLiteratureListSectionState()).literatureListSectionId!!
}
Expand All @@ -184,7 +186,7 @@ class LiteratureListService(
val steps = listOf(
LiteratureListSectionExistenceUpdateValidator(this, resourceRepository),
LiteratureListSectionUpdateValidator(resourceRepository),
LiteratureListSectionUpdater(literalService, resourceService, unsafeResourceUseCases, statementService)
LiteratureListSectionUpdater(literalService, resourceService, unsafeResourceUseCases, statementService, unsafeStatementUseCases)
)
steps.execute(command, UpdateLiteratureListSectionState())
}
Expand All @@ -210,10 +212,10 @@ class LiteratureListService(
ObservatoryValidator(observatoryRepository, { it.observatories }, { it.literatureList!!.observatories }),
LiteratureListSectionsUpdateValidator(resourceRepository),
LiteratureListResourceUpdater(unsafeResourceUseCases),
LiteratureListResearchFieldUpdater(literalService, statementService),
LiteratureListAuthorUpdater(unsafeResourceUseCases, statementService, literalService, listService, listRepository),
LiteratureListSDGUpdater(literalService, statementService),
LiteratureListSectionsUpdater(literalService, resourceService, unsafeResourceUseCases, statementService)
LiteratureListResearchFieldUpdater(literalService, statementService, unsafeStatementUseCases),
LiteratureListAuthorUpdater(unsafeResourceUseCases, statementService, unsafeStatementUseCases, literalService, listService, listRepository),
LiteratureListSDGUpdater(literalService, statementService, unsafeStatementUseCases),
LiteratureListSectionsUpdater(literalService, resourceService, unsafeResourceUseCases, statementService, unsafeStatementUseCases)
)
steps.execute(command, UpdateLiteratureListState())
}
Expand All @@ -222,10 +224,10 @@ class LiteratureListService(
val steps = listOf(
LiteratureListPublishableValidator(this),
DescriptionValidator("changelog") { it.changelog },
LiteratureListVersionCreator(resourceRepository, statementRepository, unsafeResourceUseCases, statementService, literalService, listService),
LiteratureListChangelogCreator(literalService, statementService),
LiteratureListVersionCreator(resourceRepository, statementRepository, unsafeResourceUseCases, unsafeStatementUseCases, literalService, listService),
LiteratureListChangelogCreator(literalService, unsafeStatementUseCases),
LiteratureListVersionArchiver(statementService, literatureListPublishedRepository),
LiteratureListVersionHistoryUpdater(statementService)
LiteratureListVersionHistoryUpdater(unsafeStatementUseCases)
)
return steps.execute(command, PublishLiteratureListState()).literatureListVersionId!!
}
Expand Down
Loading

0 comments on commit 72f914f

Please sign in to comment.