Skip to content

Commit

Permalink
allow to use format (dash/kebab or camel case) for rest api paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mswiderski committed Aug 30, 2024
1 parent 745429d commit eb4eb65
Show file tree
Hide file tree
Showing 12 changed files with 1,396 additions and 1,257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.automatiko.engine.api.workflow.ProcessInstanceReadMode;
import io.automatiko.engine.api.workflow.WorkItem;
import io.automatiko.engine.services.uow.UnitOfWorkExecutor;
import io.automatiko.engine.services.utils.StringUtils;

public abstract class BaseProcessInstanceManagementResource<T> implements ProcessInstanceManagement<T> {

Expand All @@ -34,6 +35,11 @@ public abstract class BaseProcessInstanceManagementResource<T> implements Proces
public BaseProcessInstanceManagementResource(Map<String, Process<?>> processData, Application application) {
this.processData = processData;
this.application = application;

for (String processId : new ArrayList<>(processData.keySet())) {
this.processData.put(StringUtils.toDashCase(processId), this.processData.get(processId));
this.processData.putIfAbsent(StringUtils.toCamelCase(processId), this.processData.get(processId));
}
}

public T doGetInstanceInError(String processId, String processInstanceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.automatiko.engine.api.workflow.VariableNotFoundException;
import io.automatiko.engine.services.uow.UnitOfWorkExecutor;
import io.automatiko.engine.services.utils.IoUtils;
import io.automatiko.engine.services.utils.StringUtils;
import io.automatiko.engine.workflow.AbstractProcess;
import io.automatiko.engine.workflow.AbstractProcessInstance;
import io.automatiko.engine.workflow.base.core.ContextContainer;
Expand Down Expand Up @@ -79,33 +80,39 @@ public class ProcessInstanceManagementResource extends BaseProcessInstanceManage

private String resourcePathPrefix;

private String resourcePathFormat;

// CDI
public ProcessInstanceManagementResource() {
this((Map<String, Process<?>>) null, null, null, Optional.empty(), Optional.empty());
this((Map<String, Process<?>>) null, null, null, Optional.empty(), Optional.empty(), Optional.empty());
}

public ProcessInstanceManagementResource(Map<String, Process<?>> process, Application application,
IdentitySupplier identitySupplier,
@ConfigProperty(name = "quarkus.automatiko.service-url") Optional<String> serviceUrl,
@ConfigProperty(name = "quarkus.automatiko.resource-path-prefix") Optional<String> resourcePathPrefix) {
@ConfigProperty(name = "quarkus.automatiko.resource-path-prefix") Optional<String> resourcePathPrefix,
@ConfigProperty(name = "quarkus.automatiko.resource-path-format") Optional<String> resourcePathFormat) {
super(process, application);
this.identitySupplier = identitySupplier;
this.exporter = new ProcessInstanceExporter(processData);
this.serviceUrl = serviceUrl.orElse(null);
this.resourcePathPrefix = resourcePathPrefix.orElse("");
this.resourcePathFormat = resourcePathFormat.orElse("");
}

@Inject
public ProcessInstanceManagementResource(Application application, Instance<Process<?>> availableProcesses,
IdentitySupplier identitySupplier,
@ConfigProperty(name = "quarkus.automatiko.service-url") Optional<String> serviceUrl,
@ConfigProperty(name = "quarkus.automatiko.resource-path-prefix") Optional<String> resourcePathPrefix) {
@ConfigProperty(name = "quarkus.automatiko.resource-path-prefix") Optional<String> resourcePathPrefix,
@ConfigProperty(name = "quarkus.automatiko.resource-path-format") Optional<String> resourcePathFormat) {
super(availableProcesses == null ? Collections.emptyMap()
: availableProcesses.stream().collect(Collectors.toMap(p -> p.id(), p -> p)), application);
this.identitySupplier = identitySupplier;
this.exporter = new ProcessInstanceExporter(processData);
this.serviceUrl = serviceUrl.orElse(null);
this.resourcePathPrefix = resourcePathPrefix.orElse("");
this.resourcePathFormat = resourcePathFormat.orElse("");
}

@Override
Expand Down Expand Up @@ -160,12 +167,17 @@ public List<ProcessDTO> get(
if (process.version() != null) {
pathprefix = "v" + process.version().replaceAll("\\.", "_") + "/";
}

String pathId = id;
if ("dash".equalsIgnoreCase(resourcePathFormat)) {
pathId = StringUtils.toDashCase(((AbstractProcess<?>) process).process().getId());
} else if ("camel".equalsIgnoreCase(resourcePathFormat)) {
pathId = StringUtils.toCamelCase(((AbstractProcess<?>) process).process().getId());
}
collected.add(new ProcessDTO(id, process.version(), process.name(),
process.description(),
(serviceUrl == null ? ""
: serviceUrl) + resourcePathPrefix + "/" + pathprefix
+ ((AbstractProcess<?>) process).process().getId()
+ pathId
+ "/image",
process.instances().size()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public IdentityProvider buildIdentityProvider(String user, List<String> roles) {
}
};
resource = spy(new ProcessInstanceManagementResource(processes, application, identitySupplier, Optional.empty(),
Optional.empty()));
Optional.empty(), Optional.empty()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public Optional<String> resourcePathPrefix() {
return Optional.empty();
};

public Optional<String> resourcePathFormat() {
return Optional.empty();
};

public Optional<String> sourceFolder() {
return Optional.empty();
};
Expand Down
Loading

0 comments on commit eb4eb65

Please sign in to comment.