Skip to content

Commit

Permalink
Fix issues with lazy initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
wederbn committed Dec 6, 2023
1 parent e3a081c commit c866453
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public interface NodeTemplateInstanceRepository extends JpaRepository<NodeTempla

List<NodeTemplateInstance> findByServiceTemplateInstanceAndTemplateId(ServiceTemplateInstance serviceTemplateInstance, String templateId);

@EntityGraph(attributePaths = {"properties"})
Optional<NodeTemplateInstance> findById(Long id);

@EntityGraph(attributePaths = {"properties"})
Optional<NodeTemplateInstance> findWithPropertiesById(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.opentosca.container.core.next.model.ServiceTemplateInstance;
import org.opentosca.container.core.next.model.ServiceTemplateInstanceProperty;
import org.opentosca.container.core.next.model.ServiceTemplateInstanceState;
import org.opentosca.container.core.next.repository.NodeTemplateInstanceRepository;
import org.opentosca.container.core.next.repository.PlanInstanceRepository;
import org.opentosca.container.core.next.repository.ServiceTemplateInstanceRepository;
import org.opentosca.container.core.next.services.templates.ServiceTemplateService;
Expand All @@ -37,18 +38,21 @@ public class ServiceTemplateInstanceService {
private final PlanInstanceRepository planInstanceRepository;
private final PlanInstanceService planInstanceService;

private final NodeTemplateInstanceRepository nodeTemplateInstanceRepository;

private final PropertyMappingsHelper helper;

public ServiceTemplateInstanceService(ServiceTemplateInstanceRepository serviceTemplateInstanceRepository,
ServiceTemplateService serviceTemplateService,
PlanInstanceRepository planInstanceRepository,
PlanInstanceService planInstanceService, CsarStorageService storage) {
PlanInstanceService planInstanceService, NodeTemplateInstanceRepository nodeTemplateInstanceRepository, CsarStorageService storage) {
this.serviceTemplateInstanceRepository = serviceTemplateInstanceRepository;
this.serviceTemplateService = serviceTemplateService;
this.planInstanceRepository = planInstanceRepository;
this.planInstanceService = planInstanceService;
this.nodeTemplateInstanceRepository = nodeTemplateInstanceRepository;

helper = new PropertyMappingsHelper(storage);
helper = new PropertyMappingsHelper(storage, this.nodeTemplateInstanceRepository);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.opentosca.container.core.next.model.NodeTemplateInstanceProperty;
import org.opentosca.container.core.next.model.ServiceTemplateInstance;
import org.opentosca.container.core.next.model.ServiceTemplateInstanceProperty;
import org.opentosca.container.core.next.repository.NodeTemplateInstanceRepository;
import org.opentosca.container.core.service.CsarStorageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,8 +38,12 @@ public class PropertyMappingsHelper {
private static final Logger logger = LoggerFactory.getLogger(PropertyMappingsHelper.class);
private final CsarStorageService storage;

public PropertyMappingsHelper(CsarStorageService storage) {

private final NodeTemplateInstanceRepository nodeTemplateInstanceRepository;

public PropertyMappingsHelper(CsarStorageService storage, NodeTemplateInstanceRepository nodeTemplateInstanceRepository) {
this.storage = storage;
this.nodeTemplateInstanceRepository = nodeTemplateInstanceRepository;
}

/**
Expand Down Expand Up @@ -200,16 +205,12 @@ private String generatePropertyValueFromConcatQuery(final String targetPropertyR
if (functionPart.trim().startsWith("'")) {
// string function part, just add to list
augmentedFunctionParts.add(functionPart.trim());
} else if (functionPart.trim().split("\\.").length == 3) {
} else if (functionPart.trim().split(".Properties.").length == 2) {
// "DSL" Query
final String[] queryParts = functionPart.trim().split("\\.");
// fast check for validity
if (!queryParts[1].equals("Properties")) {
return null;
}
final String[] queryParts = functionPart.trim().split(".Properties.");

final String nodeTemplateName = queryParts[0];
final String propertyName = queryParts[2];
final String propertyName = queryParts[1];

if (getNodeInstanceWithName(nodeInstance, nodeTemplateName) != null) {

Expand Down Expand Up @@ -239,7 +240,7 @@ private NodeTemplateInstance getNodeInstanceWithName(final Collection<NodeTempla

for (final NodeTemplateInstance nodeInstance : nodeInstances) {
if (nodeInstance.getTemplateId().equals(nodeTemplateId)) {
return nodeInstance;
return nodeTemplateInstanceRepository.findById(nodeInstance.getId()).get();
}
}

Expand Down

0 comments on commit c866453

Please sign in to comment.