Skip to content

Commit

Permalink
Core - API - Fix to oqm core interacting entity getting improperly im…
Browse files Browse the repository at this point in the history
…ported
  • Loading branch information
GregJohnStewart committed Jul 30, 2024
1 parent a4c7ba8 commit 026834c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.ebp.oqm.core.api.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.Getter;
Expand Down Expand Up @@ -31,30 +32,34 @@ public CoreApiInteractingEntity(
){
this.email = email;
}

@Getter
private String email;


@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@Override
public ObjectId getId() {
return BS_ID;
}


@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@Override
public String getName() {
return "Core API";
}


@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@Override
public InteractingEntityType getInteractingEntityType() {
return InteractingEntityType.CORE_API;
}


@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@Override
public Set<String> getRoles() {
return new HashSet<>(){{add("Yes");}};
}

@Override
public boolean updateFrom(JsonWebToken jwt) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bson.codecs.pojo.annotations.BsonDiscriminator;
import org.eclipse.microprofile.jwt.Claims;
import org.eclipse.microprofile.jwt.JsonWebToken;
import tech.ebp.oqm.core.api.config.CoreApiInteractingEntity;
import tech.ebp.oqm.core.api.model.object.AttKeywordMainObject;
import tech.ebp.oqm.core.api.model.object.interactingEntity.externalService.GeneralService;
import tech.ebp.oqm.core.api.model.object.interactingEntity.externalService.plugin.PluginService;
Expand All @@ -29,6 +30,7 @@
@JsonSubTypes.Type(value = User.class, name = "USER"),
@JsonSubTypes.Type(value = PluginService.class, name = "SERVICE_PLUGIN"),
@JsonSubTypes.Type(value = GeneralService.class, name = "SERVICE_GENERAL"),
@JsonSubTypes.Type(value = CoreApiInteractingEntity.class, name = "CORE_API"),
})
@BsonDiscriminator
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ private static List<File> getObjectHistoryFiles(Path directory) throws IOExcepti
@Inject
OqmDatabaseService oqmDatabaseService;

@Inject
InteractingEntityService interactingEntityService;

@Inject
CustomUnitService customUnitService;

@Inject
ImageService imageService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import jakarta.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import tech.ebp.oqm.core.api.config.CoreApiInteractingEntity;
import tech.ebp.oqm.core.api.model.object.MainObject;
import tech.ebp.oqm.core.api.model.object.ObjectUtils;
import tech.ebp.oqm.core.api.model.object.interactingEntity.InteractingEntity;
Expand All @@ -20,13 +22,18 @@
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@ApplicationScoped
public class InteractingEntityImporter extends TopLevelImporter<EntityImportResult> {

@Inject
@Getter(AccessLevel.PRIVATE)
InteractingEntityService interactingEntityService;

@Inject
@Getter(AccessLevel.PRIVATE)
CoreApiInteractingEntity coreApiInteractingEntity;


@Override
public Path getObjectDirPath(Path topLevelPath) {
Expand All @@ -51,11 +58,20 @@ public EntityImportResult readInObjectsImpl(
long addedEntityCount = 0;

for(File curEntityDataFile : getObjectFiles(directory)){
log.debug("Reading in interacting entity from file {}", curEntityDataFile.getName());

if(curEntityDataFile.getName().startsWith(this.getCoreApiInteractingEntity().getId().toHexString())){
log.info("File contains core api interacting entity. Skipping.");
continue;
}

InteractingEntity importingUser = ObjectUtils.OBJECT_MAPPER.readValue(curEntityDataFile, InteractingEntity.class);
//if we already have this exact user
if(existentUserIds.contains(importingUser.getId())){
log.info("Interacting entity already present.");
continue;
}
log.debug("Importing interacting entity: {}", importingUser);

ObjectId hit = null;
if(options.getInteractingEntityMapStrategies().contains(InteractingEntityMapStrategy.EMAIL)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ protected MongoDbAwareService(
// }

protected MongoCollection<T> getCollection(DbCacheEntry db) {
log.debug("Getting collection for cache entry {}", db);
if(!this.collections.containsKey(db.getDbId())){
log.info("Collection for db cache entry not present. Creating. Cache entry: {}", db);
this.collections.put(
db.getDbId(),
db.getMongoDatabase().getCollection(this.collectionName, this.clazz)
Expand Down

0 comments on commit 026834c

Please sign in to comment.