Skip to content

Commit

Permalink
Make the redirection service optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kerim1 committed Sep 5, 2023
1 parent 4fadc24 commit 87bdb82
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,19 @@ public UUID createEntity(Collection collection, Optional<Collection> baseCollect

dataStoreOperations.createEntity(collection, baseCollection, createEntity);

afterSuccessTaskExecutor.addTask(
new AddPersistentUrlTask(
redirectionService,
uriToRedirectToFromPersistentUrls.apply(collection.getCollectionName(), id, 1),
ImmutableEntityLookup.builder()
.rev(1)
.timId(id)
.collection(collection.getCollectionName())
.build()
)
);
if (redirectionService != null) {
afterSuccessTaskExecutor.addTask(
new AddPersistentUrlTask(
redirectionService,
uriToRedirectToFromPersistentUrls.apply(collection.getCollectionName(), id, 1),
ImmutableEntityLookup.builder()
.rev(1)
.timId(id)
.collection(collection.getCollectionName())
.build()
)
);
}

return id;
}
Expand All @@ -96,17 +98,20 @@ public void replaceEntity(Collection collection, UpdateEntity updateEntity, User
updateEntity.setModified(createChange(user));

int rev = dataStoreOperations.replaceEntity(collection, updateEntity);
afterSuccessTaskExecutor.addTask(
new AddPersistentUrlTask(
redirectionService,
uriToRedirectToFromPersistentUrls.apply(collection.getCollectionName(), updateEntity.getId(), rev),
ImmutableEntityLookup.builder()
.rev(rev)
.timId(updateEntity.getId())
.collection(collection.getCollectionName())
.build()
)
);

if (redirectionService != null) {
afterSuccessTaskExecutor.addTask(
new AddPersistentUrlTask(
redirectionService,
uriToRedirectToFromPersistentUrls.apply(collection.getCollectionName(), updateEntity.getId(), rev),
ImmutableEntityLookup.builder()
.rev(rev)
.timId(updateEntity.getId())
.collection(collection.getCollectionName())
.build()
)
);
}
}
//FIXME: when adding the new datamodel. We need to fix the persistent url generator. It now generates a url per
// collection, but writes to a property that exists regardless of the collection. It also generates a new persistent
Expand All @@ -118,18 +123,19 @@ public void deleteEntity(Collection collection, UUID uuid, User user)

int rev = dataStoreOperations.deleteEntity(collection, uuid, createChange(user));


afterSuccessTaskExecutor.addTask(
new AddPersistentUrlTask(
redirectionService,
uriToRedirectToFromPersistentUrls.apply(collection.getCollectionName(), uuid, rev),
ImmutableEntityLookup.builder()
.rev(rev)
.timId(uuid)
.collection(collection.getCollectionName())
.build()
)
);
if (redirectionService != null) {
afterSuccessTaskExecutor.addTask(
new AddPersistentUrlTask(
redirectionService,
uriToRedirectToFromPersistentUrls.apply(collection.getCollectionName(), uuid, rev),
ImmutableEntityLookup.builder()
.rev(rev)
.timId(uuid)
.collection(collection.getCollectionName())
.build()
)
);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import nl.knaw.huygens.timbuctoo.v5.util.TimbuctooRdfIdHelper;
import org.immutables.value.Value;

import javax.annotation.Nullable;
import javax.validation.Valid;
import javax.ws.rs.DefaultValue;
import java.net.URI;
Expand Down Expand Up @@ -90,10 +91,10 @@ public HttpClientConfiguration getHttpClientConfiguration() {
public abstract Optional<DatabaseBackupperFactory> getDatabaseBackupper();

@Valid
@Nullable
@JsonProperty("redirectionService")
public abstract RedirectionServiceFactory getRedirectionServiceFactory();


public abstract String getArchetypesSchema();

public abstract Optional<URI> getUserRedirectUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,8 @@ public void run(TimbuctooConfiguration configuration, Environment environment) t
register(environment, "dataStoreAvailabilityCheck", new DatabaseAvailabilityCheck(dataSetRepository));

RedirectionServiceFactory redirectionServiceFactory = configuration.getRedirectionServiceFactory();
RedirectionService redirectionService = redirectionServiceFactory.makeRedirectionService(
new ActiveMqManager(activeMqBundle), dataSetRepository
);

RedirectionService redirectionService = redirectionServiceFactory != null ?
redirectionServiceFactory.makeRedirectionService(new ActiveMqManager(activeMqBundle), dataSetRepository) : null;

// TODO make function when TimbuctooActions does not depend on TransactionEnforcer anymore
TimbuctooActions.TimbuctooActionsFactory timbuctooActionsFactory = new TimbuctooActions.TimbuctooActionsFactoryImpl(
Expand All @@ -249,7 +247,9 @@ public void run(TimbuctooConfiguration configuration, Environment environment) t
);
graphManager.onGraph(g -> new ScaffoldMigrator(graphManager).execute());

redirectionService.init(transactionEnforcer);
if (redirectionService != null) {
redirectionService.init(transactionEnforcer);
}

final Vres vres = new DatabaseConfiguredVres(transactionEnforcer);
migrations.put("prepare-for-bia-import-migration", new PrepareForBiaImportMigration(vres, graphManager));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,29 @@ public PersistEntityMutation(Runnable schemaUpdater, RedirectionService redirect

@Override
public Object executeAction(DataFetchingEnvironment env) {
User user = MutationHelpers.getUser(env);
String graph = env.getArgument("graph");
String entityUri = env.getArgument("entityUri");
URI uri;
try {
if (graph != null) {
uri = GetEntityInGraph.makeUrl(ownerId, dataSetName, graph, entityUri);
} else {
uri = GetEntity.makeUrl(ownerId, dataSetName, entityUri);
if (redirectionService != null) {
User user = MutationHelpers.getUser(env);
String graph = env.getArgument("graph");
String entityUri = env.getArgument("entityUri");
URI uri;
try {
if (graph != null) {
uri = GetEntityInGraph.makeUrl(ownerId, dataSetName, graph, entityUri);
} else {
uri = GetEntity.makeUrl(ownerId, dataSetName, entityUri);
}
} catch (UnsupportedEncodingException e) {
return ImmutableMap.of("message", "Request for persistent Uri failed.");
}
} catch (UnsupportedEncodingException e) {
return ImmutableMap.of("message", "Request for persistent Uri failed.");
}
URI fullUri = uriHelper.fromResourceUri(uri);
URI fullUri = uriHelper.fromResourceUri(uri);

EntityLookup entityLookup =
ImmutableEntityLookup.builder().dataSetId(dataSetId).uri(entityUri).user(user).build();
redirectionService.add(fullUri, entityLookup);

EntityLookup entityLookup = ImmutableEntityLookup.builder().dataSetId(dataSetId).uri(entityUri).user(user).build();
redirectionService.add(fullUri, entityLookup);
return ImmutableMap.of("message", "Request for persistent Uri accepted");
}

return ImmutableMap.of("message", "Request for persistent Uri accepted");
return ImmutableMap.of("message", "Request for persistent Uri failed: no service configured!");
}
}

0 comments on commit 87bdb82

Please sign in to comment.