Skip to content

Commit

Permalink
Merge pull request #20 from swisscom/bugfix/various
Browse files Browse the repository at this point in the history
Bugfix/various
  • Loading branch information
sabberworm authored Oct 29, 2024
2 parents 29669b4 + 57162df commit 2e50157
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/main/frontend/model/Run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ export class Run {
private async loadMessages(response: Promise<Response>) {
for await (const message of streamingFetch<Message>(await response)) {
if (typeof message !== 'string') {
if (message.type === 'file' && message.data) {
message.blob = new Blob([decodeBase64(message.data)], { type: message.mime });
if (message.type === 'file') {
const data = message.data ? decodeBase64(message.data) : new Uint8Array(0);
message.blob = new Blob([data], { type: message.mime });
delete message.data;
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/frontend/sections/editor/types/EachStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ export const EachStep = forwardRef<HTMLDivElement, { parentHops: Hop[]; hop: Typ
<h5>JEXL Expression</h5>
<p>The sub-pipeline given will be repeated for every element this expression produces.</p>
<h5>Iterator</h5>
<p>This is the name of the variable used to address the individual item.</p>
<p>
This is the name of the variable used to address the individual item.
<br />
The item index will be available as{' '}
<code>
${'{'}iterator{'}'}_index
</code>
</p>
</Help>
</StepEditor>
);
Expand Down
9 changes: 7 additions & 2 deletions src/main/frontend/sections/output/FileMessageOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Elm = styled('div')`
border-radius: 12px;
display: grid;
gap: 6px;
grid-template-areas: 'icon name . download' 'icon type . download';
grid-template-areas: 'icon name name download' 'icon type size download';
grid-template-columns: max-content max-content 1fr max-content;
> coral-icon {
grid-area: icon;
Expand All @@ -28,6 +28,9 @@ const Elm = styled('div')`
> .type {
grid-area: type;
}
> .size {
grid-area: size;
}
> a {
grid-area: download;
}
Expand Down Expand Up @@ -71,13 +74,15 @@ function iconFor(mimeType: MimeType): CoralIcon {

export const FileMessageOutput: FC<{ message: FileMessage }> = ({ message }) => {
const icon = iconFor(message.mime);
const blob = message.blob!;

return (
<Elm>
<coral-icon icon={icon} size="L" />
<span className="name">{message.name}</span>
<small className="type">{message.mime}</small>
<a href={URL.createObjectURL(message.blob!)} download={message.name}>
<small className="size">{blob.size} bytes</small>
<a href={URL.createObjectURL(blob)} download={message.name}>
<button type="button" is="coral-button" icon="download">
Download
</button>
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/com/swisscom/aem/tools/impl/hops/Each.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.swisscom.aem.tools.jcrhopper.context.HopContext;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
Expand All @@ -25,25 +27,30 @@ public class Each implements Hop<Each.Config> {
@Override
public void run(Config config, Node node, HopContext context) throws RepositoryException, HopperException {
final Object items = context.evaluate(config.expression);
int index = 0;
if (items instanceof Iterable) {
for (Object item : (Iterable<?>) items) {
runWith(config, item, node, context);
runWith(config, item, index++, node, context);
}
} else if (items instanceof Iterator) {
while (((Iterator<?>) items).hasNext()) {
runWith(config, ((Iterator<?>) items).next(), node, context);
runWith(config, ((Iterator<?>) items).next(), index++, node, context);
}
} else if (items.getClass().isArray()) {
for (Object item : (Object[]) items) {
runWith(config, item, node, context);
runWith(config, item, index++, node, context);
}
} else {
runWith(config, items, node, context);
runWith(config, items, index, node, context);
}
}

@SuppressFBWarnings(value = "ITC_INHERITANCE_TYPE_CHECKING", justification = "The item comes from scripting and can be an arbitrary type")
private void runWith(Config config, Object item, Node initialNode, HopContext context) throws HopperException, RepositoryException {
@SuppressFBWarnings(
value = { "ITC_INHERITANCE_TYPE_CHECKING", "STT_TOSTRING_MAP_KEYING" },
justification = "The item comes from scripting and can be an arbitrary type. Dynamic Lookup Required."
)
private void runWith(Config config, Object item, int index, Node initialNode, HopContext context)
throws HopperException, RepositoryException {
Node node = initialNode;
if (config.assumeNodes) {
if (item instanceof Node) {
Expand All @@ -59,7 +66,10 @@ private void runWith(Config config, Object item, Node initialNode, HopContext co
} else {
context.debug("Iterating non-node value {} accessible as {}", item, config.iterator);
}
context.runHops(node, config.hops, Collections.singletonMap(config.iterator, item));
final Map<String, Object> vars = new HashMap<>();
vars.put(config.iterator, item);
vars.put(config.iterator + "_index", index);
context.runHops(node, config.hops, vars);
}

@Nonnull
Expand Down

0 comments on commit 2e50157

Please sign in to comment.