From b36930ae98d87676650b36a59ceae7ec4b759ff9 Mon Sep 17 00:00:00 2001 From: Zdenek Vales Date: Sun, 9 Feb 2020 16:44:11 +0100 Subject: [PATCH] #21: Fix for problem with CompatibilityDao not being wired into the apicomp service. Empty fields in CompatibilityCheckResult initialized. --- .../impl/ApiCompatibilityCheckerServiceImpl.java | 9 ++++++--- .../apicomp/result/CompatibilityCheckResult.java | 5 ++++- .../crce/compatibility/dao/internal/Activator.java | 13 ++++++------- .../dao/internal/CompatibilityDaoMongoImpl.java | 4 ++++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/ApiCompatibilityCheckerServiceImpl.java b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/ApiCompatibilityCheckerServiceImpl.java index 92594fee..92e50998 100644 --- a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/ApiCompatibilityCheckerServiceImpl.java +++ b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/ApiCompatibilityCheckerServiceImpl.java @@ -9,6 +9,7 @@ import cz.zcu.kiv.crce.compatibility.dao.CompatibilityDao; import cz.zcu.kiv.crce.metadata.Resource; import org.apache.felix.dm.annotation.api.Component; +import org.apache.felix.dm.annotation.api.ServiceDependency; import org.osgi.framework.Constants; import org.osgi.service.cm.ConfigurationException; import org.osgi.service.cm.ManagedService; @@ -36,7 +37,8 @@ public class ApiCompatibilityCheckerServiceImpl implements ApiCompatibilityCheck private List availableCheckers; -// @ServiceDependency + // todo: find out why this doesn't work + @ServiceDependency(required = false) private volatile CompatibilityDao compatibilityDao; public ApiCompatibilityCheckerServiceImpl() { @@ -63,7 +65,7 @@ public CompatibilityCheckResult compareApis(Resource api1, Resource api2) { @Override public Compatibility findExistingCompatibility(Resource api1, Resource api2) { if (compatibilityDao == null) { - logger.warn("Compatibility dao not set."); + logger.warn("Compatibility dao not available, can't find existing compatibility object."); return null; } List compatibilities = compatibilityDao.findCompatibility(api1, api2); @@ -73,9 +75,10 @@ public Compatibility findExistingCompatibility(Resource api1, Resource api2) { @Override public Compatibility saveCompatibility(Compatibility compatibilityCheckResult) { if (compatibilityDao == null) { - logger.warn("Compatibility dao not set."); + logger.warn("Compatibility dao not available, can't save compatibility object."); return compatibilityCheckResult; } + return compatibilityDao.saveCompatibility(compatibilityCheckResult); } diff --git a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/result/CompatibilityCheckResult.java b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/result/CompatibilityCheckResult.java index cc5786f4..fa576fa0 100644 --- a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/result/CompatibilityCheckResult.java +++ b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/result/CompatibilityCheckResult.java @@ -62,6 +62,9 @@ public CompatibilityCheckResult(Resource baseResource, Resource resource) { this(); baseResourceName = baseResource.getId(); resourceName = resource.getId(); + + baseResourceVersion = new Version(0,0,0); + resourceVersion = new Version(0,0,0); } @Override @@ -116,6 +119,6 @@ public void setDiffDetails(List diffDetails) { @Nonnull @Override public Contract getContract() { - return null; + return Contract.INTERACTION; } } diff --git a/modules/crce-compatibility-dao-mongodb/src/main/java/cz/zcu/kiv/crce/compatibility/dao/internal/Activator.java b/modules/crce-compatibility-dao-mongodb/src/main/java/cz/zcu/kiv/crce/compatibility/dao/internal/Activator.java index f79be05a..fdc218e8 100644 --- a/modules/crce-compatibility-dao-mongodb/src/main/java/cz/zcu/kiv/crce/compatibility/dao/internal/Activator.java +++ b/modules/crce-compatibility-dao-mongodb/src/main/java/cz/zcu/kiv/crce/compatibility/dao/internal/Activator.java @@ -1,15 +1,13 @@ package cz.zcu.kiv.crce.compatibility.dao.internal; -import java.util.Dictionary; -import java.util.Hashtable; - +import cz.zcu.kiv.crce.compatibility.dao.CompatibilityDao; import org.apache.felix.dm.DependencyActivatorBase; import org.apache.felix.dm.DependencyManager; import org.osgi.framework.BundleContext; import org.osgi.service.cm.ManagedService; -import cz.zcu.kiv.crce.compatibility.CompatibilityFactory; -import cz.zcu.kiv.crce.compatibility.dao.CompatibilityDao; +import java.util.Dictionary; +import java.util.Hashtable; /** * Date: 17.11.13 @@ -39,8 +37,9 @@ public void init(BundleContext context, DependencyManager manager) throws Except .setInterface(s, compatibilityProps) .setFactory(new CompatibilityDaoMongoFactory(), "get") //requires CompatibilityFactory for proper mapping - .add(createServiceDependency().setRequired(true) - .setService(CompatibilityFactory.class)) +// .add(createServiceDependency().setRequired(false) +// .setService(CompatibilityFactory.class) +// ) ); } diff --git a/modules/crce-compatibility-dao-mongodb/src/main/java/cz/zcu/kiv/crce/compatibility/dao/internal/CompatibilityDaoMongoImpl.java b/modules/crce-compatibility-dao-mongodb/src/main/java/cz/zcu/kiv/crce/compatibility/dao/internal/CompatibilityDaoMongoImpl.java index 14b61630..344f9fd8 100644 --- a/modules/crce-compatibility-dao-mongodb/src/main/java/cz/zcu/kiv/crce/compatibility/dao/internal/CompatibilityDaoMongoImpl.java +++ b/modules/crce-compatibility-dao-mongodb/src/main/java/cz/zcu/kiv/crce/compatibility/dao/internal/CompatibilityDaoMongoImpl.java @@ -6,6 +6,7 @@ import cz.zcu.kiv.crce.compatibility.Difference; import cz.zcu.kiv.crce.compatibility.dao.CompatibilityDao; import cz.zcu.kiv.crce.compatibility.dao.internal.mapping.MongoCompatibilityMapper; +import cz.zcu.kiv.crce.compatibility.impl.DefaultCompatibilityFactoryImpl; import cz.zcu.kiv.crce.metadata.Resource; import cz.zcu.kiv.crce.metadata.dao.mongodb.BaseMongoDao; import cz.zcu.kiv.crce.metadata.type.Version; @@ -42,6 +43,9 @@ public class CompatibilityDaoMongoImpl extends BaseMongoDao implements Compatibi public CompatibilityDaoMongoImpl(MongoClient client) { super(client); this.col = getCollection("compatibility"); + + // todo: service or just like this? probably should be service + factory = new DefaultCompatibilityFactoryImpl(); } @Override