-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5634aea
commit 92ec79f
Showing
22 changed files
with
677 additions
and
146 deletions.
There are no files selected for viewing
38 changes: 23 additions & 15 deletions
38
...rc/main/java/io/camunda/connector/runtime/core/document/AggregatingOperationExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...untime-core/src/main/java/io/camunda/connector/runtime/core/document/DocumentFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...r-runtime-core/src/main/java/io/camunda/connector/runtime/core/document/DocumentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
23 changes: 20 additions & 3 deletions
23
...e/src/main/java/io/camunda/connector/runtime/core/document/DocumentOperationExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...-core/src/main/java/io/camunda/connector/runtime/core/document/InMemoryDocumentStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
...rc/main/java/io/camunda/connector/runtime/core/document/client/DocumentCreateRequest.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
.../src/main/java/io/camunda/connector/runtime/core/document/client/DocumentStoreClient.java
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...ntime-core/src/main/java/io/camunda/connector/runtime/core/document/jackson/Document.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.