Skip to content

Commit

Permalink
prepare end-to-end draft
Browse files Browse the repository at this point in the history
  • Loading branch information
chillleader committed Aug 7, 2024
1 parent 5634aea commit 92ec79f
Show file tree
Hide file tree
Showing 22 changed files with 677 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.core.document;

import io.camunda.connector.api.document.DocumentReference.DocumentOperationReference;
import java.util.Map;
import io.camunda.connector.api.document.Document;
import io.camunda.connector.api.document.DocumentOperation;

public class AggregatingOperationExecutor implements DocumentOperationExecutor {

private final Map<String, DocumentOperationExecutor> executors;

public AggregatingOperationExecutor(Map<String, DocumentOperationExecutor> executors) {
this.executors = executors;
}
public AggregatingOperationExecutor() {}

@Override
public String getName() {
return "";
public boolean matches(DocumentOperation operationReference) {
return true;
}

@Override
public Object execute(DocumentOperationReference operationReference) {
DocumentOperationExecutor executor = executors.get(operationReference.operation().name());
if (executor == null) {
throw new IllegalArgumentException("No executor found for operation " + operationReference.operation().name());
}
return executor.execute(operationReference);
public Object execute(DocumentOperation operationReference, Document document) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.core.document;

import io.camunda.connector.api.document.DocumentSource;
import io.camunda.connector.api.document.DocumentSource.ReferenceDocumentSource;
import java.util.Map;

public class DocumentFactory {

private final DocumentStore documentStore;

public DocumentFactory(DocumentStore documentStore) {
this.documentStore = documentStore;
}

public DocumentCreationMetadataStep from(DocumentSource source) {
return new DocumentCreationMetadataStep(documentStore, source);
}

public static class DocumentCreationMetadataStep {

private final DocumentStore documentStore;
private final DocumentSource source;

private Map<String, Object> metadata;

public DocumentCreationMetadataStep(DocumentStore documentStore, DocumentSource source) {
this.documentStore = documentStore;
this.source = source;
}

public DocumentCreationMetadataStep metadata(String key, Object value) {
metadata.put(key, value);
return this;
}

public DocumentCreationMetadataStep metadata(Map<String, Object> metadataKeys) {
metadata.putAll(metadataKeys);
return this;
}

public DocumentImpl build() {
if (source instanceof ReferenceDocumentSource refSource) {
return new DocumentImpl(metadata, refSource.reference(), documentStore);
}
// TODO: support external documents
throw new IllegalArgumentException(
"Unsupported document source type: " + source.getClass().getName());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.core.document;

import io.camunda.connector.api.document.Document;
import io.camunda.connector.api.document.DocumentMetadata;
import io.camunda.connector.api.document.DocumentReference;
import java.io.InputStream;
import java.util.Base64;
import java.util.Map;

public class DocumentImpl implements Document {

private final DocumentMetadata metadata;
private final DocumentReference reference;
private final DocumentStore documentStore;

public DocumentImpl(
Map<String, Object> metadata, DocumentReference reference, DocumentStore documentStore) {
this.metadata = new DocumentMetadata(metadata);
this.reference = reference;
this.documentStore = documentStore;
}

@Override
public DocumentMetadata metadata() {
return metadata;
}

@Override
public String asBase64() {
return Base64.getEncoder().encodeToString(asByteArray());
}

@Override
public InputStream asInputStream() {
return documentStore.getDocumentContentStream(reference);
}

@Override
public byte[] asByteArray() {
return documentStore.getDocumentContent(reference);
}

@Override
public DocumentReference reference() {
return reference;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.core.document;

import io.camunda.connector.api.document.DocumentReference.DocumentOperationReference;
import io.camunda.connector.api.document.Document;
import io.camunda.connector.api.document.DocumentOperation;

public interface DocumentOperationExecutor {

String getName();
boolean matches(DocumentOperation operationReference);

Object execute(DocumentOperationReference operationReference);
Object execute(DocumentOperation operationReference, Document document);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.api.document;
package io.camunda.connector.runtime.core.document;

import java.util.Map;
import io.camunda.connector.api.document.DocumentMetadata;
import io.camunda.connector.api.document.DocumentReference;
import java.io.InputStream;

public record BasicDocument(DocumentMetadata metadata, DocumentSource source) implements Document {
public interface DocumentStore {

public static Builder builder() {
return new Builder();
}
DocumentReference createDocument(DocumentMetadata metadata, byte[] content);

public static class Builder {
private Map<String, Object> metadata;
private DocumentSource source;
DocumentReference createDocument(DocumentMetadata metadata, InputStream content);

public Builder metadata(Map<String, Object> metadata) {
this.metadata = metadata;
return this;
}
byte[] getDocumentContent(DocumentReference reference);

public Builder source(DocumentSource source) {
this.source = null;
return this;
}
InputStream getDocumentContentStream(DocumentReference reference);

public BasicDocument build() {

return new BasicDocument(metadata, source);
}
}
void deleteDocument(DocumentReference reference);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.core.document;

import io.camunda.connector.api.document.DocumentMetadata;
import io.camunda.connector.api.document.DocumentReference;
import io.camunda.connector.api.document.DocumentReference.CamundaDocumentReference;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class InMemoryDocumentStore implements DocumentStore {

public static final String STORE_ID = "in-memory";

private final Map<UUID, byte[]> documents = new HashMap<>();

@Override
public DocumentReference createDocument(DocumentMetadata metadata, byte[] content) {
var id = UUID.randomUUID();
documents.put(id, content);
return new CamundaDocumentReference(STORE_ID, id.toString(), metadata.getKeys(), null);
}

@Override
public DocumentReference createDocument(DocumentMetadata metadata, InputStream content) {
var id = UUID.randomUUID();
try {
documents.put(id, content.readAllBytes());
} catch (Exception e) {
throw new RuntimeException(e);
}
return new CamundaDocumentReference(STORE_ID, id.toString(), metadata.getKeys(), null);
}

@Override
public byte[] getDocumentContent(DocumentReference reference) {
if (!(reference instanceof CamundaDocumentReference ref)) {
throw new IllegalArgumentException(
"Unsupported document reference type: " + reference.getClass().getName());
}
if (!STORE_ID.equals(ref.storeId())) {
throw new IllegalArgumentException("Unsupported store id: " + ref.storeId());
}
return documents.get(UUID.fromString(ref.documentId()));
}

@Override
public InputStream getDocumentContentStream(DocumentReference reference) {
if (!(reference instanceof CamundaDocumentReference ref)) {
throw new IllegalArgumentException(
"Unsupported document reference type: " + reference.getClass().getName());
}
if (!STORE_ID.equals(ref.storeId())) {
throw new IllegalArgumentException("Unsupported store id: " + ref.storeId());
}
return new ByteArrayInputStream(documents.get(UUID.fromString(ref.documentId())));
}

@Override
public void deleteDocument(DocumentReference reference) {
if (!(reference instanceof CamundaDocumentReference ref)) {
throw new IllegalArgumentException(
"Unsupported document reference type: " + reference.getClass().getName());
}
if (!STORE_ID.equals(ref.storeId())) {
throw new IllegalArgumentException("Unsupported store id: " + ref.storeId());
}
documents.remove(UUID.fromString(ref.documentId()));
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 92ec79f

Please sign in to comment.