Skip to content

Commit

Permalink
Merge pull request #150 from xm-online/remove_experemental_api_usage
Browse files Browse the repository at this point in the history
Remove lombock experementral api usage
  • Loading branch information
sergeysenja1992 committed Jun 11, 2024
2 parents fdc44e4 + fa73d71 commit f5aed98
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rootProject.name=activation
profile=dev

version=2.0.60
version=2.0.61

# Build properties
node_version=12.13.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
import com.icthh.xm.commons.lep.api.LepAdditionalContextField;
import com.icthh.xm.commons.lep.api.LepBaseKey;
import com.icthh.xm.commons.lep.api.LepEngine;
import com.icthh.xm.commons.lep.commons.CommonsExecutor;
import com.icthh.xm.tmf.ms.activation.config.TaskLepAdditionalContext.TaskContext;
import com.icthh.xm.tmf.ms.activation.domain.SagaEvent;
import com.icthh.xm.tmf.ms.activation.domain.SagaLog;
import com.icthh.xm.tmf.ms.activation.domain.SagaLogType;
import com.icthh.xm.tmf.ms.activation.domain.SagaTransaction;
import com.icthh.xm.tmf.ms.activation.repository.SagaLogRepository;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static com.icthh.xm.tmf.ms.activation.config.TaskLepAdditionalContext.TaskContextField.FIELD_NAME;
import static com.icthh.xm.tmf.ms.activation.domain.SagaLogType.EVENT_END;
import static com.icthh.xm.tmf.ms.activation.domain.SagaLogType.EVENT_START;
import static java.util.Collections.emptyMap;


@Slf4j
@Component
@RequiredArgsConstructor
public class TaskLepAdditionalContext implements LepAdditionalContext<TaskContext> {
Expand Down Expand Up @@ -70,15 +72,14 @@ default TaskContext getTasks() {
}

// need to implement all methods from Map interface for js lep-s interop
@Slf4j
@RequiredArgsConstructor
public static class TaskContext implements Map<String, Object> {

private final SagaLogRepository sagaLogRepository;
private final SagaTransaction sagaTransaction;
private final SagaEvent sagaEvent;
private final Map<String, Object> context = new HashMap<>();
@Delegate(excludes = MapExcludes.class)
private final Map<String, Object> delegate = emptyMap();

@Override
public Object get(Object inputTaskTypeKey) {
Expand All @@ -91,11 +92,12 @@ public Object get(Object inputTaskTypeKey) {
}

return context.computeIfAbsent(taskTypeKey, key -> {
List<SagaLog> logs = sagaLogRepository.getLogsBySagaTransactionIdAndTypeKey(sagaTransaction.getId(), taskTypeKey);
return Map.of(
"input", filterContext(logs, EVENT_START),
"output", filterContext(logs, EVENT_END)
);
List<SagaLog> logs = sagaLogRepository.getLogsBySagaTransactionIdAndTypeKey(sagaTransaction.getId(), taskTypeKey);
log.info("Logs by taskTypeKey {} and transactionId {} | {}", taskTypeKey, sagaTransaction.getId(), logs);
return Map.of(
"input", filterContext(logs, EVENT_START),
"output", filterContext(logs, EVENT_END)
);
}
);
}
Expand All @@ -113,9 +115,64 @@ private static Map<String, Object> filterContext(List<SagaLog> logs, SagaLogType
.orElse(emptyMap());
}

public interface MapExcludes {
Object get(Object key);
boolean containsKey(Object key);
@Override
public Object remove(Object arg0) {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public boolean equals(Object arg0) {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public Collection<Object> values() {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public int hashCode() {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public void clear() {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public boolean isEmpty() {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public int size() {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public Set<Entry<String, Object>> entrySet() {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public void putAll(Map<? extends String, ?> arg0) {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public boolean containsValue(Object arg0) {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public Set<String> keySet() {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public Object put(String key, Object value) {
throw new UnsupportedOperationException("Not implemented");
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.icthh.xm.tmf.ms.activation;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -13,17 +14,22 @@
*/
public class LepTestLinkScanner {

private static String SEPARATOR = File.separator;

private static String PROJECT_ROOT = Paths.get("").toAbsolutePath().toString();
private static String XM_REPOSITORY_HOME;

private static final String XM_MS_NAME = "activation";

private static final String XM_REPOSITORY_TENANTS = "config/tenants";
private static final String XM_REPOSITORY_MS_TEST = XM_MS_NAME + "/test";
private static final String XM_REPOSITORY_MS_LEP = XM_MS_NAME + "/lep";
private static final String XM_REPOSITORY_TENANTS = "config".concat(SEPARATOR).concat("tenants");
private static final String XM_REPOSITORY_MS_TEST = XM_MS_NAME.concat(SEPARATOR).concat("test");
private static final String XM_REPOSITORY_MS_LEP = XM_MS_NAME.concat(SEPARATOR).concat("lep");
private static final String XM_COMMONS_MS_LEP = "commons".concat(SEPARATOR).concat("lep");

private static final String LEP_TEST_HOME = "src/test/lep";
private static final String LEP_SCRIPT_HOME = "src/main/lep";
private static final String LEP_TEST_HOME = "src".concat(SEPARATOR).concat("test").concat(SEPARATOR).concat("lep");
private static final String LEP_SCRIPT_HOME = "src".concat(SEPARATOR).concat("main").concat(SEPARATOR).concat("lep");
private static final String TEST_RESOURCE_HOME = "src".concat(SEPARATOR).concat("test").concat(SEPARATOR).concat("resources");
private static final String XM_CONFIG_TEST_RESOURCE_HOME = TEST_RESOURCE_HOME.concat(SEPARATOR).concat("config").concat(SEPARATOR).concat("tenants");

private static final String LEP_TEST_EXISTS_REGEX = ".*tenants/.*/" + XM_MS_NAME + "/test";

Expand Down Expand Up @@ -54,6 +60,32 @@ public static void main(String[] args) throws IOException {
.peek(SymLink::createSymLink)
.count();

Path envCommonsPath = Paths.get(XM_REPOSITORY_HOME, XM_REPOSITORY_TENANTS, XM_COMMONS_MS_LEP);
if (Files.exists(envCommonsPath)) {
var symLink = new SymLink(
Paths.get(PROJECT_ROOT, LEP_SCRIPT_HOME, XM_COMMONS_MS_LEP),
envCommonsPath
);
if (!Files.exists(symLink.from)) {
System.out.println("Create env commons link");
symLink.createSymLink();
count++;
}
}

Path pathToAllConfigs = Paths.get(XM_REPOSITORY_HOME, XM_REPOSITORY_TENANTS);
if (Files.exists(pathToAllConfigs)) {
var symLink = new SymLink(
Paths.get(PROJECT_ROOT, XM_CONFIG_TEST_RESOURCE_HOME),
pathToAllConfigs
);
if (!Files.exists(symLink.from)) {
System.out.println("Create config link as resource");
symLink.createSymLink();
count++;
}
}

System.out.println("created links count: " + count);

}
Expand Down

0 comments on commit f5aed98

Please sign in to comment.