Skip to content

Commit

Permalink
chore: incorporate latest changes of EDC (eclipse-edc#264)
Browse files Browse the repository at this point in the history
* chore: adapt to latest EDC changes

* DEPENDENCIES

* DEPENDENCIES-2
  • Loading branch information
paullatzelsperger authored Feb 6, 2024
1 parent 2393fdf commit 8db22f3
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 21 deletions.
1 change: 0 additions & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ maven/mavencentral/org.apache.velocity/velocity-engine-core/2.3, Apache-2.0, app
maven/mavencentral/org.apache.velocity/velocity-engine-scripting/2.3, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.assertj/assertj-core/3.25.1, Apache-2.0, approved, #12585
maven/mavencentral/org.assertj/assertj-core/3.25.2, Apache-2.0, approved, #12585
maven/mavencentral/org.assertj/assertj-core/3.25.3, Apache-2.0, approved, #12585
maven/mavencentral/org.awaitility/awaitility/4.2.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.bouncycastle/bcpkix-jdk18on/1.72, MIT, approved, #3789
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Metaform Systems, Inc.
* Copyright (c) 2024 Metaform Systems, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
Expand All @@ -14,27 +14,26 @@

package org.eclipse.edc.identityhub.defaults;

import org.eclipse.edc.connector.core.store.CriterionToPredicateConverterImpl;
import org.eclipse.edc.connector.core.store.ReflectionPropertyLookup;
import org.eclipse.edc.identityhub.spi.model.VerifiableCredentialResource;
import org.eclipse.edc.spi.query.CriterionToPredicateConverter;
import org.eclipse.edc.identitytrust.model.VerifiableCredentialContainer;
import org.eclipse.edc.spi.types.PathItem;
import org.eclipse.edc.util.reflection.ReflectionUtil;

import java.time.Instant;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
* This converts a Criterion to a Predicate, that can be used to query a {@link Stream} of {@link VerifiableCredentialResource} objects.
* <p>
* Since the object graph of a {@link org.eclipse.edc.identitytrust.model.VerifiableCredential} is quite open, some special handling is required, e.g. for the
* {@code credentialSubject} object.
* This class performs the lookup of properties in a {@link VerifiableCredentialResource}.
* There is some special handling for raw JSON properties like the {@link VerifiableCredentialContainer#rawVc()} and the {@code credentialSubject}, as the latter is
* basically schema-less.
*/
public class CriterionToCredentialResourceConverter extends CriterionToPredicateConverterImpl implements CriterionToPredicateConverter {
public class CredentialResourceLookup extends ReflectionPropertyLookup {
@Override
protected Object property(String key, Object object) {
var fieldValue = super.property(key, object);
public Object getProperty(String key, Object object) {
var fieldValue = super.getProperty(key, object);
if (fieldValue instanceof Instant) {
fieldValue = fieldValue.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected String getId(VerifiableCredentialResource newObject) {

@Override
protected QueryResolver<VerifiableCredentialResource> createQueryResolver() {
return new ReflectionBasedQueryResolver<>(VerifiableCredentialResource.class, new CriterionToCredentialResourceConverter());
criterionOperatorRegistry.registerPropertyLookup(new CredentialResourceLookup());
return new ReflectionBasedQueryResolver<>(VerifiableCredentialResource.class, criterionOperatorRegistry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package org.eclipse.edc.identityhub.defaults;

import org.eclipse.edc.connector.core.store.CriterionOperatorRegistryImpl;
import org.eclipse.edc.spi.query.CriterionOperatorRegistry;
import org.eclipse.edc.spi.query.QueryResolver;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.result.StoreResult;
Expand All @@ -34,7 +36,13 @@
abstract class InMemoryEntityStore<T> {
protected final Map<String, T> store = new HashMap<>();
protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
protected final QueryResolver<T> queryResolver = createQueryResolver();
protected final QueryResolver<T> queryResolver;
protected final CriterionOperatorRegistry criterionOperatorRegistry;

protected InMemoryEntityStore() {
criterionOperatorRegistry = CriterionOperatorRegistryImpl.ofDefaults();
queryResolver = createQueryResolver();
}

/**
* Creates a new entity if none exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package org.eclipse.edc.identityhub.defaults;

import org.eclipse.edc.connector.core.store.CriterionToPredicateConverterImpl;
import org.eclipse.edc.connector.core.store.ReflectionBasedQueryResolver;
import org.eclipse.edc.identityhub.spi.model.KeyPairResource;
import org.eclipse.edc.identityhub.spi.store.KeyPairResourceStore;
Expand All @@ -28,7 +27,7 @@ protected String getId(KeyPairResource newObject) {

@Override
protected QueryResolver<KeyPairResource> createQueryResolver() {
return new ReflectionBasedQueryResolver<>(KeyPairResource.class, new CriterionToPredicateConverterImpl());
return new ReflectionBasedQueryResolver<>(KeyPairResource.class, criterionOperatorRegistry);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package org.eclipse.edc.identityhub.defaults;

import org.eclipse.edc.connector.core.store.CriterionToPredicateConverterImpl;
import org.eclipse.edc.connector.core.store.ReflectionBasedQueryResolver;
import org.eclipse.edc.identityhub.spi.model.participant.ParticipantContext;
import org.eclipse.edc.identityhub.spi.store.ParticipantContextStore;
Expand All @@ -31,6 +30,6 @@ protected String getId(ParticipantContext newObject) {

@Override
protected QueryResolver<ParticipantContext> createQueryResolver() {
return new ReflectionBasedQueryResolver<>(ParticipantContext.class, new CriterionToPredicateConverterImpl());
return new ReflectionBasedQueryResolver<>(ParticipantContext.class, criterionOperatorRegistry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import org.eclipse.edc.identithub.did.spi.store.DidResourceStore;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.spi.query.CriterionOperatorRegistry;
import org.eclipse.edc.spi.system.ServiceExtension;

import static org.eclipse.edc.identityhub.did.defaults.DidDefaultServicesExtension.NAME;
Expand All @@ -25,13 +27,16 @@
public class DidDefaultServicesExtension implements ServiceExtension {
public static final String NAME = "DID Default Services Extension";

@Inject
private CriterionOperatorRegistry criterionOperatorRegistry;

@Override
public String name() {
return NAME;
}

@Provider(isDefault = true)
public DidResourceStore createInMemoryDidResourceStore() {
return new InMemoryDidResourceStore();
return new InMemoryDidResourceStore(criterionOperatorRegistry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.edc.connector.core.store.ReflectionBasedQueryResolver;
import org.eclipse.edc.identithub.did.spi.model.DidResource;
import org.eclipse.edc.identithub.did.spi.store.DidResourceStore;
import org.eclipse.edc.spi.query.CriterionOperatorRegistry;
import org.eclipse.edc.spi.query.QueryResolver;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.result.StoreResult;
Expand All @@ -32,8 +33,11 @@
public class InMemoryDidResourceStore implements DidResourceStore {
private final Map<String, DidResource> store = new HashMap<>();
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private final QueryResolver<DidResource> queryResolver = new ReflectionBasedQueryResolver<>(DidResource.class);
private final QueryResolver<DidResource> queryResolver;

public InMemoryDidResourceStore(CriterionOperatorRegistry criterionOperatorRegistry) {
queryResolver = new ReflectionBasedQueryResolver<>(DidResource.class, criterionOperatorRegistry);
}

@Override
public StoreResult<Void> save(DidResource resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

package org.eclipse.edc.identityhub.did.defaults;

import org.eclipse.edc.connector.core.store.CriterionOperatorRegistryImpl;
import org.eclipse.edc.identithub.did.spi.store.DidResourceStore;
import org.eclipse.edc.identityhub.did.store.test.DidResourceStoreTestBase;

class InMemoryDidResourceStoreTest extends DidResourceStoreTestBase {

private final DidResourceStore store = new InMemoryDidResourceStore();
private final DidResourceStore store = new InMemoryDidResourceStore(CriterionOperatorRegistryImpl.ofDefaults());

@Override
protected DidResourceStore getStore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.edc.identityhub.keypairs;

import org.eclipse.edc.identityhub.spi.KeyPairService;
import org.eclipse.edc.identityhub.spi.events.diddocument.DidDocumentPublished;
import org.eclipse.edc.identityhub.spi.events.keypair.KeyPairObservable;
import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextCreated;
import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextDeleted;
Expand Down Expand Up @@ -56,6 +57,7 @@ public KeyPairService createParticipantService(ServiceExtensionContext context)
var service = new KeyPairServiceImpl(keyPairResourceStore, vault, context.getMonitor(), keyPairObservable());
eventRouter.registerSync(ParticipantContextCreated.class, service);
eventRouter.registerSync(ParticipantContextDeleted.class, service);
eventRouter.registerSync(DidDocumentPublished.class, service);
return service;
}

Expand Down

0 comments on commit 8db22f3

Please sign in to comment.