Search in sources :

Example 26 with Attachment

use of com.ibm.cloud.cloudant.v1.model.Attachment in project cloudant-java-sdk by IBM.

the class DocumentTest method testDocument.

@Test
public void testDocument() throws Throwable {
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    assertEquals(attachmentModel.contentType(), "testString");
    assertEquals(attachmentModel.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
    assertEquals(attachmentModel.digest(), "testString");
    assertEquals(attachmentModel.encodedLength(), Long.valueOf("0"));
    assertEquals(attachmentModel.encoding(), "testString");
    assertEquals(attachmentModel.follows(), Boolean.valueOf(true));
    assertEquals(attachmentModel.length(), Long.valueOf("0"));
    assertEquals(attachmentModel.revpos(), Long.valueOf("1"));
    assertEquals(attachmentModel.stub(), Boolean.valueOf(true));
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    assertEquals(revisionsModel.ids(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(revisionsModel.start(), Long.valueOf("1"));
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    assertEquals(documentRevisionStatusModel.rev(), "testString");
    assertEquals(documentRevisionStatusModel.status(), "available");
    Document documentModel = new Document.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("foo", "testString").build();
    assertEquals(documentModel.getAttachments(), new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    });
    assertEquals(documentModel.getConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(documentModel.isDeleted(), Boolean.valueOf(true));
    assertEquals(documentModel.getDeletedConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(documentModel.getId(), "testString");
    assertEquals(documentModel.getLocalSeq(), "testString");
    assertEquals(documentModel.getRev(), "testString");
    assertEquals(documentModel.getRevisions(), revisionsModel);
    assertEquals(documentModel.getRevsInfo(), new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel)));
    assertEquals(documentModel.get("foo"), "testString");
    String json = TestUtilities.serialize(documentModel);
    Document documentModelNew = TestUtilities.deserialize(json, Document.class);
    assertTrue(documentModelNew instanceof Document);
    assertEquals(documentModelNew.isDeleted(), Boolean.valueOf(true));
    assertEquals(documentModelNew.getId(), "testString");
    assertEquals(documentModelNew.getLocalSeq(), "testString");
    assertEquals(documentModelNew.getRev(), "testString");
    assertEquals(documentModelNew.getRevisions().toString(), revisionsModel.toString());
    assertEquals(documentModelNew.get("foo"), "testString");
}
Also used : ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) Document(com.ibm.cloud.cloudant.v1.model.Document) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) Test(org.testng.annotations.Test)

Example 27 with Attachment

use of com.ibm.cloud.cloudant.v1.model.Attachment in project cloudant-java-sdk by IBM.

the class ReplicationDocumentTest method testReplicationDocument.

@Test
public void testReplicationDocument() throws Throwable {
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    assertEquals(attachmentModel.contentType(), "testString");
    assertEquals(attachmentModel.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
    assertEquals(attachmentModel.digest(), "testString");
    assertEquals(attachmentModel.encodedLength(), Long.valueOf("0"));
    assertEquals(attachmentModel.encoding(), "testString");
    assertEquals(attachmentModel.follows(), Boolean.valueOf(true));
    assertEquals(attachmentModel.length(), Long.valueOf("0"));
    assertEquals(attachmentModel.revpos(), Long.valueOf("1"));
    assertEquals(attachmentModel.stub(), Boolean.valueOf(true));
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    assertEquals(revisionsModel.ids(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(revisionsModel.start(), Long.valueOf("1"));
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    assertEquals(documentRevisionStatusModel.rev(), "testString");
    assertEquals(documentRevisionStatusModel.status(), "available");
    ReplicationCreateTargetParameters replicationCreateTargetParametersModel = new ReplicationCreateTargetParameters.Builder().n(Long.valueOf("1")).partitioned(false).q(Long.valueOf("26")).build();
    assertEquals(replicationCreateTargetParametersModel.n(), Long.valueOf("1"));
    assertEquals(replicationCreateTargetParametersModel.partitioned(), Boolean.valueOf(false));
    assertEquals(replicationCreateTargetParametersModel.q(), Long.valueOf("26"));
    ReplicationDatabaseAuthBasic replicationDatabaseAuthBasicModel = new ReplicationDatabaseAuthBasic.Builder().password("testString").username("testString").build();
    assertEquals(replicationDatabaseAuthBasicModel.password(), "testString");
    assertEquals(replicationDatabaseAuthBasicModel.username(), "testString");
    ReplicationDatabaseAuthIam replicationDatabaseAuthIamModel = new ReplicationDatabaseAuthIam.Builder().apiKey("testString").build();
    assertEquals(replicationDatabaseAuthIamModel.apiKey(), "testString");
    ReplicationDatabaseAuth replicationDatabaseAuthModel = new ReplicationDatabaseAuth.Builder().basic(replicationDatabaseAuthBasicModel).iam(replicationDatabaseAuthIamModel).build();
    assertEquals(replicationDatabaseAuthModel.basic(), replicationDatabaseAuthBasicModel);
    assertEquals(replicationDatabaseAuthModel.iam(), replicationDatabaseAuthIamModel);
    ReplicationDatabase replicationDatabaseModel = new ReplicationDatabase.Builder().auth(replicationDatabaseAuthModel).headers(new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    }).url("testString").build();
    assertEquals(replicationDatabaseModel.auth(), replicationDatabaseAuthModel);
    assertEquals(replicationDatabaseModel.headers(), new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    });
    assertEquals(replicationDatabaseModel.url(), "testString");
    UserContext userContextModel = new UserContext.Builder().db("testString").name("testString").roles(new java.util.ArrayList<String>(java.util.Arrays.asList("_reader"))).build();
    assertEquals(userContextModel.db(), "testString");
    assertEquals(userContextModel.name(), "testString");
    assertEquals(userContextModel.roles(), new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
    ReplicationDocument replicationDocumentModel = new ReplicationDocument.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).cancel(true).checkpointInterval(Long.valueOf("0")).connectionTimeout(Long.valueOf("0")).continuous(false).createTarget(false).createTargetParams(replicationCreateTargetParametersModel).docIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).filter("testString").httpConnections(Long.valueOf("1")).queryParams(new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    }).retriesPerRequest(Long.valueOf("0")).selector(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).sinceSeq("testString").socketOptions("testString").source(replicationDatabaseModel).sourceProxy("testString").target(replicationDatabaseModel).targetProxy("testString").useCheckpoints(true).userCtx(userContextModel).workerBatchSize(Long.valueOf("1")).workerProcesses(Long.valueOf("1")).add("foo", "testString").build();
    assertEquals(replicationDocumentModel.getAttachments(), new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    });
    assertEquals(replicationDocumentModel.getConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(replicationDocumentModel.isDeleted(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModel.getDeletedConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(replicationDocumentModel.getId(), "testString");
    assertEquals(replicationDocumentModel.getLocalSeq(), "testString");
    assertEquals(replicationDocumentModel.getRev(), "testString");
    assertEquals(replicationDocumentModel.getRevisions(), revisionsModel);
    assertEquals(replicationDocumentModel.getRevsInfo(), new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel)));
    assertEquals(replicationDocumentModel.isCancel(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModel.getCheckpointInterval(), Long.valueOf("0"));
    assertEquals(replicationDocumentModel.getConnectionTimeout(), Long.valueOf("0"));
    assertEquals(replicationDocumentModel.isContinuous(), Boolean.valueOf(false));
    assertEquals(replicationDocumentModel.isCreateTarget(), Boolean.valueOf(false));
    assertEquals(replicationDocumentModel.getCreateTargetParams(), replicationCreateTargetParametersModel);
    assertEquals(replicationDocumentModel.getDocIds(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(replicationDocumentModel.getFilter(), "testString");
    assertEquals(replicationDocumentModel.getHttpConnections(), Long.valueOf("1"));
    assertEquals(replicationDocumentModel.getQueryParams(), new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    });
    assertEquals(replicationDocumentModel.getRetriesPerRequest(), Long.valueOf("0"));
    assertEquals(replicationDocumentModel.getSelector(), new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    });
    assertEquals(replicationDocumentModel.getSinceSeq(), "testString");
    assertEquals(replicationDocumentModel.getSocketOptions(), "testString");
    assertEquals(replicationDocumentModel.getSource(), replicationDatabaseModel);
    assertEquals(replicationDocumentModel.getSourceProxy(), "testString");
    assertEquals(replicationDocumentModel.getTarget(), replicationDatabaseModel);
    assertEquals(replicationDocumentModel.getTargetProxy(), "testString");
    assertEquals(replicationDocumentModel.isUseCheckpoints(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModel.getUserCtx(), userContextModel);
    assertEquals(replicationDocumentModel.getWorkerBatchSize(), Long.valueOf("1"));
    assertEquals(replicationDocumentModel.getWorkerProcesses(), Long.valueOf("1"));
    assertEquals(replicationDocumentModel.get("foo"), "testString");
    String json = TestUtilities.serialize(replicationDocumentModel);
    ReplicationDocument replicationDocumentModelNew = TestUtilities.deserialize(json, ReplicationDocument.class);
    assertTrue(replicationDocumentModelNew instanceof ReplicationDocument);
    assertEquals(replicationDocumentModelNew.isDeleted(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModelNew.getId(), "testString");
    assertEquals(replicationDocumentModelNew.getLocalSeq(), "testString");
    assertEquals(replicationDocumentModelNew.getRev(), "testString");
    assertEquals(replicationDocumentModelNew.getRevisions().toString(), revisionsModel.toString());
    assertEquals(replicationDocumentModelNew.isCancel(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModelNew.getCheckpointInterval(), Long.valueOf("0"));
    assertEquals(replicationDocumentModelNew.getConnectionTimeout(), Long.valueOf("0"));
    assertEquals(replicationDocumentModelNew.isContinuous(), Boolean.valueOf(false));
    assertEquals(replicationDocumentModelNew.isCreateTarget(), Boolean.valueOf(false));
    assertEquals(replicationDocumentModelNew.getCreateTargetParams().toString(), replicationCreateTargetParametersModel.toString());
    assertEquals(replicationDocumentModelNew.getFilter(), "testString");
    assertEquals(replicationDocumentModelNew.getHttpConnections(), Long.valueOf("1"));
    assertEquals(replicationDocumentModelNew.getRetriesPerRequest(), Long.valueOf("0"));
    assertEquals(replicationDocumentModelNew.getSinceSeq(), "testString");
    assertEquals(replicationDocumentModelNew.getSocketOptions(), "testString");
    assertEquals(replicationDocumentModelNew.getSource().toString(), replicationDatabaseModel.toString());
    assertEquals(replicationDocumentModelNew.getSourceProxy(), "testString");
    assertEquals(replicationDocumentModelNew.getTarget().toString(), replicationDatabaseModel.toString());
    assertEquals(replicationDocumentModelNew.getTargetProxy(), "testString");
    assertEquals(replicationDocumentModelNew.isUseCheckpoints(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModelNew.getUserCtx().toString(), userContextModel.toString());
    assertEquals(replicationDocumentModelNew.getWorkerBatchSize(), Long.valueOf("1"));
    assertEquals(replicationDocumentModelNew.getWorkerProcesses(), Long.valueOf("1"));
    assertEquals(replicationDocumentModelNew.get("foo"), "testString");
}
Also used : ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) ReplicationDatabaseAuthBasic(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuthBasic) ReplicationDatabaseAuthIam(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuthIam) UserContext(com.ibm.cloud.cloudant.v1.model.UserContext) ReplicationCreateTargetParameters(com.ibm.cloud.cloudant.v1.model.ReplicationCreateTargetParameters) ReplicationDatabase(com.ibm.cloud.cloudant.v1.model.ReplicationDatabase) ReplicationDatabaseAuth(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuth) Test(org.testng.annotations.Test)

Example 28 with Attachment

use of com.ibm.cloud.cloudant.v1.model.Attachment in project cloudant-java-sdk by IBM.

the class PutReplicationDocumentOptionsTest method testPutReplicationDocumentOptions.

@Test
public void testPutReplicationDocumentOptions() throws Throwable {
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    assertEquals(attachmentModel.contentType(), "testString");
    assertEquals(attachmentModel.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
    assertEquals(attachmentModel.digest(), "testString");
    assertEquals(attachmentModel.encodedLength(), Long.valueOf("0"));
    assertEquals(attachmentModel.encoding(), "testString");
    assertEquals(attachmentModel.follows(), Boolean.valueOf(true));
    assertEquals(attachmentModel.length(), Long.valueOf("0"));
    assertEquals(attachmentModel.revpos(), Long.valueOf("1"));
    assertEquals(attachmentModel.stub(), Boolean.valueOf(true));
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    assertEquals(revisionsModel.ids(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(revisionsModel.start(), Long.valueOf("1"));
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    assertEquals(documentRevisionStatusModel.rev(), "testString");
    assertEquals(documentRevisionStatusModel.status(), "available");
    ReplicationCreateTargetParameters replicationCreateTargetParametersModel = new ReplicationCreateTargetParameters.Builder().n(Long.valueOf("1")).partitioned(false).q(Long.valueOf("26")).build();
    assertEquals(replicationCreateTargetParametersModel.n(), Long.valueOf("1"));
    assertEquals(replicationCreateTargetParametersModel.partitioned(), Boolean.valueOf(false));
    assertEquals(replicationCreateTargetParametersModel.q(), Long.valueOf("26"));
    ReplicationDatabaseAuthBasic replicationDatabaseAuthBasicModel = new ReplicationDatabaseAuthBasic.Builder().password("testString").username("testString").build();
    assertEquals(replicationDatabaseAuthBasicModel.password(), "testString");
    assertEquals(replicationDatabaseAuthBasicModel.username(), "testString");
    ReplicationDatabaseAuthIam replicationDatabaseAuthIamModel = new ReplicationDatabaseAuthIam.Builder().apiKey("testString").build();
    assertEquals(replicationDatabaseAuthIamModel.apiKey(), "testString");
    ReplicationDatabaseAuth replicationDatabaseAuthModel = new ReplicationDatabaseAuth.Builder().basic(replicationDatabaseAuthBasicModel).iam(replicationDatabaseAuthIamModel).build();
    assertEquals(replicationDatabaseAuthModel.basic(), replicationDatabaseAuthBasicModel);
    assertEquals(replicationDatabaseAuthModel.iam(), replicationDatabaseAuthIamModel);
    ReplicationDatabase replicationDatabaseModel = new ReplicationDatabase.Builder().auth(replicationDatabaseAuthModel).headers(new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    }).url("testString").build();
    assertEquals(replicationDatabaseModel.auth(), replicationDatabaseAuthModel);
    assertEquals(replicationDatabaseModel.headers(), new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    });
    assertEquals(replicationDatabaseModel.url(), "testString");
    UserContext userContextModel = new UserContext.Builder().db("testString").name("testString").roles(new java.util.ArrayList<String>(java.util.Arrays.asList("_reader"))).build();
    assertEquals(userContextModel.db(), "testString");
    assertEquals(userContextModel.name(), "testString");
    assertEquals(userContextModel.roles(), new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
    ReplicationDocument replicationDocumentModel = new ReplicationDocument.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).cancel(true).checkpointInterval(Long.valueOf("0")).connectionTimeout(Long.valueOf("0")).continuous(false).createTarget(false).createTargetParams(replicationCreateTargetParametersModel).docIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).filter("testString").httpConnections(Long.valueOf("1")).queryParams(new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    }).retriesPerRequest(Long.valueOf("0")).selector(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).sinceSeq("testString").socketOptions("testString").source(replicationDatabaseModel).sourceProxy("testString").target(replicationDatabaseModel).targetProxy("testString").useCheckpoints(true).userCtx(userContextModel).workerBatchSize(Long.valueOf("1")).workerProcesses(Long.valueOf("1")).add("foo", "testString").build();
    assertEquals(replicationDocumentModel.getAttachments(), new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    });
    assertEquals(replicationDocumentModel.getConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(replicationDocumentModel.isDeleted(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModel.getDeletedConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(replicationDocumentModel.getId(), "testString");
    assertEquals(replicationDocumentModel.getLocalSeq(), "testString");
    assertEquals(replicationDocumentModel.getRev(), "testString");
    assertEquals(replicationDocumentModel.getRevisions(), revisionsModel);
    assertEquals(replicationDocumentModel.getRevsInfo(), new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel)));
    assertEquals(replicationDocumentModel.isCancel(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModel.getCheckpointInterval(), Long.valueOf("0"));
    assertEquals(replicationDocumentModel.getConnectionTimeout(), Long.valueOf("0"));
    assertEquals(replicationDocumentModel.isContinuous(), Boolean.valueOf(false));
    assertEquals(replicationDocumentModel.isCreateTarget(), Boolean.valueOf(false));
    assertEquals(replicationDocumentModel.getCreateTargetParams(), replicationCreateTargetParametersModel);
    assertEquals(replicationDocumentModel.getDocIds(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(replicationDocumentModel.getFilter(), "testString");
    assertEquals(replicationDocumentModel.getHttpConnections(), Long.valueOf("1"));
    assertEquals(replicationDocumentModel.getQueryParams(), new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    });
    assertEquals(replicationDocumentModel.getRetriesPerRequest(), Long.valueOf("0"));
    assertEquals(replicationDocumentModel.getSelector(), new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    });
    assertEquals(replicationDocumentModel.getSinceSeq(), "testString");
    assertEquals(replicationDocumentModel.getSocketOptions(), "testString");
    assertEquals(replicationDocumentModel.getSource(), replicationDatabaseModel);
    assertEquals(replicationDocumentModel.getSourceProxy(), "testString");
    assertEquals(replicationDocumentModel.getTarget(), replicationDatabaseModel);
    assertEquals(replicationDocumentModel.getTargetProxy(), "testString");
    assertEquals(replicationDocumentModel.isUseCheckpoints(), Boolean.valueOf(true));
    assertEquals(replicationDocumentModel.getUserCtx(), userContextModel);
    assertEquals(replicationDocumentModel.getWorkerBatchSize(), Long.valueOf("1"));
    assertEquals(replicationDocumentModel.getWorkerProcesses(), Long.valueOf("1"));
    assertEquals(replicationDocumentModel.get("foo"), "testString");
    PutReplicationDocumentOptions putReplicationDocumentOptionsModel = new PutReplicationDocumentOptions.Builder().docId("testString").replicationDocument(replicationDocumentModel).ifMatch("testString").batch("ok").newEdits(false).rev("testString").build();
    assertEquals(putReplicationDocumentOptionsModel.docId(), "testString");
    assertEquals(putReplicationDocumentOptionsModel.replicationDocument(), replicationDocumentModel);
    assertEquals(putReplicationDocumentOptionsModel.ifMatch(), "testString");
    assertEquals(putReplicationDocumentOptionsModel.batch(), "ok");
    assertEquals(putReplicationDocumentOptionsModel.newEdits(), Boolean.valueOf(false));
    assertEquals(putReplicationDocumentOptionsModel.rev(), "testString");
}
Also used : ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) ReplicationDatabaseAuthBasic(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuthBasic) ReplicationDatabaseAuthIam(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuthIam) UserContext(com.ibm.cloud.cloudant.v1.model.UserContext) PutReplicationDocumentOptions(com.ibm.cloud.cloudant.v1.model.PutReplicationDocumentOptions) ReplicationCreateTargetParameters(com.ibm.cloud.cloudant.v1.model.ReplicationCreateTargetParameters) ReplicationDatabase(com.ibm.cloud.cloudant.v1.model.ReplicationDatabase) ReplicationDatabaseAuth(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuth) Test(org.testng.annotations.Test)

Example 29 with Attachment

use of com.ibm.cloud.cloudant.v1.model.Attachment in project CRD by HL7-DaVinci.

the class LibraryContentProcessor method base64EncodeToAttachment.

private Attachment base64EncodeToAttachment(FileResource fileResource, String mimeType) {
    Attachment attachment = new Attachment();
    try {
        // base64 encode
        InputStream inputStream = fileResource.getResource().getInputStream();
        byte[] byteData = new byte[inputStream.available()];
        inputStream.read(byteData);
        String encodedData = Base64.encodeBase64String(byteData);
        attachment.setContentType(mimeType);
        Base64BinaryType b64bType = new Base64BinaryType();
        b64bType.setValueAsString(encodedData);
        attachment.setDataElement(b64bType);
    } catch (IOException e) {
        logger.warn("failed to read the data: " + mimeType);
    }
    return attachment;
}
Also used : InputStream(java.io.InputStream) Attachment(org.hl7.fhir.r4.model.Attachment) IOException(java.io.IOException) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType)

Example 30 with Attachment

use of com.ibm.cloud.cloudant.v1.model.Attachment in project MobileAccessGateway by i4mi.

the class Iti67ResponseConverter method translateToFhir.

@Override
public List<DocumentReference> translateToFhir(QueryResponse input, Map<String, Object> parameters) {
    ArrayList<DocumentReference> list = new ArrayList<DocumentReference>();
    if (input != null && Status.SUCCESS.equals(input.getStatus())) {
        // process relationship association
        Map<String, List<DocumentReferenceRelatesToComponent>> relatesToMapping = new HashMap<String, List<DocumentReferenceRelatesToComponent>>();
        for (Association association : input.getAssociations()) {
            // Relationship type -> relatesTo.code code [1..1]
            // relationship reference -> relatesTo.target Reference(DocumentReference)
            String source = association.getSourceUuid();
            String target = association.getTargetUuid();
            AssociationType type = association.getAssociationType();
            DocumentReferenceRelatesToComponent relatesTo = new DocumentReferenceRelatesToComponent();
            if (type != null)
                switch(type) {
                    case APPEND:
                        relatesTo.setCode(DocumentRelationshipType.APPENDS);
                        break;
                    case REPLACE:
                        relatesTo.setCode(DocumentRelationshipType.REPLACES);
                        break;
                    case TRANSFORM:
                        relatesTo.setCode(DocumentRelationshipType.TRANSFORMS);
                        break;
                    case SIGNS:
                        relatesTo.setCode(DocumentRelationshipType.SIGNS);
                        break;
                }
            relatesTo.setTarget(new Reference().setReference("urn:oid:" + target));
            if (!relatesToMapping.containsKey(source))
                relatesToMapping.put(source, new ArrayList<DocumentReferenceRelatesToComponent>());
            relatesToMapping.get(source).add(relatesTo);
        }
        if (input.getDocumentEntries() != null) {
            for (DocumentEntry documentEntry : input.getDocumentEntries()) {
                DocumentReference documentReference = new DocumentReference();
                // FIXME do we need to cache this id in
                documentReference.setId(noUuidPrefix(documentEntry.getEntryUuid()));
                // relation to the DocumentManifest itself
                // for
                list.add(documentReference);
                // limitedMetadata -> meta.profile canonical [0..*]
                if (documentEntry.isLimitedMetadata()) {
                    documentReference.getMeta().addProfile("http://ihe.net/fhir/StructureDefinition/IHE_MHD_Query_Comprehensive_DocumentReference");
                } else {
                    documentReference.getMeta().addProfile("http://ihe.net/fhir/StructureDefinition/IHE_MHD_Comprehensive_DocumentManifest");
                }
                // uniqueId -> masterIdentifier Identifier [0..1] [1..1]
                if (documentEntry.getUniqueId() != null) {
                    documentReference.setMasterIdentifier((new Identifier().setValue("urn:oid:" + documentEntry.getUniqueId())));
                }
                // DocumentReference.identifier. use shall be ‘official’
                if (documentEntry.getEntryUuid() != null) {
                    documentReference.addIdentifier((new Identifier().setSystem("urn:ietf:rfc:3986").setValue(asUuid(documentEntry.getEntryUuid()))).setUse(IdentifierUse.OFFICIAL));
                }
                // Other status values are allowed but are not defined in this mapping to XDS.
                if (AvailabilityStatus.APPROVED.equals(documentEntry.getAvailabilityStatus())) {
                    documentReference.setStatus(DocumentReferenceStatus.CURRENT);
                }
                if (AvailabilityStatus.DEPRECATED.equals(documentEntry.getAvailabilityStatus())) {
                    documentReference.setStatus(DocumentReferenceStatus.SUPERSEDED);
                }
                // contentTypeCode -> type CodeableConcept [0..1]
                if (documentEntry.getTypeCode() != null) {
                    documentReference.setType(transform(documentEntry.getTypeCode()));
                }
                // classCode -> category CodeableConcept [0..*]
                if (documentEntry.getClassCode() != null) {
                    documentReference.addCategory((transform(documentEntry.getClassCode())));
                }
                // representing the XDS Affinity Domain Patient.
                if (documentEntry.getPatientId() != null) {
                    Identifiable patient = documentEntry.getPatientId();
                    documentReference.setSubject(transformPatient(patient));
                }
                // creationTime -> date instant [0..1]
                if (documentEntry.getCreationTime() != null) {
                    documentReference.setDate(Date.from(documentEntry.getCreationTime().getDateTime().toInstant()));
                }
                // PractitionerRole| Organization| Device| Patient| RelatedPerson) [0..*]
                if (documentEntry.getAuthors() != null) {
                    for (Author author : documentEntry.getAuthors()) {
                        documentReference.addAuthor(transformAuthor(author));
                    }
                }
                // legalAuthenticator -> authenticator Note 1
                // Reference(Practitioner|Practition erRole|Organization [0..1]
                Person person = documentEntry.getLegalAuthenticator();
                if (person != null) {
                    Practitioner practitioner = transformPractitioner(person);
                    documentReference.setAuthenticator((Reference) new Reference().setResource(practitioner));
                }
                // Relationship Association -> relatesTo [0..*]
                // [1..1]
                documentReference.setRelatesTo(relatesToMapping.get(documentEntry.getEntryUuid()));
                // title -> description string [0..1]
                if (documentEntry.getTitle() != null) {
                    documentReference.setDescription(documentEntry.getTitle().getValue());
                }
                // DocumentReference itself.
                if (documentEntry.getConfidentialityCodes() != null) {
                    documentReference.addSecurityLabel(transform(documentEntry.getConfidentialityCodes()));
                }
                DocumentReferenceContentComponent content = documentReference.addContent();
                Attachment attachment = new Attachment();
                content.setAttachment(attachment);
                // mimeType -> content.attachment.contentType [1..1] code [0..1]
                if (documentEntry.getMimeType() != null) {
                    attachment.setContentType(documentEntry.getMimeType());
                }
                // languageCode -> content.attachment.language code [0..1]
                if (documentEntry.getLanguageCode() != null) {
                    attachment.setLanguage(documentEntry.getLanguageCode());
                }
                // retrievable location of the document -> content.attachment.url uri
                // [0..1] [1..1
                // has to defined, for the PoC we define
                // $host:port/camel/$repositoryid/$uniqueid
                attachment.setUrl(config.getUriMagXdsRetrieve() + "?uniqueId=" + documentEntry.getUniqueId() + "&repositoryUniqueId=" + documentEntry.getRepositoryUniqueId());
                // size -> content.attachment.size integer [0..1] The size is calculated
                if (documentEntry.getSize() != null) {
                    attachment.setSize(documentEntry.getSize().intValue());
                }
                // on the data prior to base64 encoding, if the data is base64 encoded.
                if (documentEntry.getHash() != null) {
                    attachment.setHash(Hex.fromHex(documentEntry.getHash()));
                }
                // comments -> content.attachment.title string [0..1]
                if (documentEntry.getComments() != null) {
                    attachment.setTitle(documentEntry.getComments().getValue());
                }
                // TcreationTime -> content.attachment.creation dateTime [0..1]
                if (documentEntry.getCreationTime() != null) {
                    attachment.setCreation(Date.from(documentEntry.getCreationTime().getDateTime().toInstant()));
                }
                // formatCode -> content.format Coding [0..1]
                if (documentEntry.getFormatCode() != null) {
                    content.setFormat(transform(documentEntry.getFormatCode()).getCodingFirstRep());
                }
                DocumentReferenceContextComponent context = new DocumentReferenceContextComponent();
                documentReference.setContext(context);
                // referenceIdList -> context.encounter Reference(Encounter) [0..*] When
                // referenceIdList contains an encounter, and a FHIR Encounter is available, it
                // may be referenced.
                // Map to context.related
                List<ReferenceId> refIds = documentEntry.getReferenceIdList();
                if (refIds != null) {
                    for (ReferenceId refId : refIds) {
                        context.getRelated().add(transform(refId));
                    }
                }
                // eventCodeList -> context.event CodeableConcept [0..*]
                if (documentEntry.getEventCodeList() != null) {
                    documentReference.getContext().setEvent(transformMultiple(documentEntry.getEventCodeList()));
                }
                // serviceStartTime serviceStopTime -> context.period Period [0..1]
                if (documentEntry.getServiceStartTime() != null || documentEntry.getServiceStopTime() != null) {
                    Period period = new Period();
                    period.setStartElement(transform(documentEntry.getServiceStartTime()));
                    period.setEndElement(transform(documentEntry.getServiceStopTime()));
                    documentReference.getContext().setPeriod(period);
                }
                // [0..1]
                if (documentEntry.getHealthcareFacilityTypeCode() != null) {
                    context.setFacilityType(transform(documentEntry.getHealthcareFacilityTypeCode()));
                }
                // practiceSettingCode -> context.practiceSetting CodeableConcept [0..1]
                if (documentEntry.getPracticeSettingCode() != null) {
                    context.setPracticeSetting(transform(documentEntry.getPracticeSettingCode()));
                }
                // sourcePatientId and sourcePatientInfo -> context.sourcePatientInfo
                // Reference(Patient) [0..1] Contained Patient Resource with
                // Patient.identifier.use element set to ‘usual’.
                Identifiable sourcePatientId = documentEntry.getSourcePatientId();
                PatientInfo sourcePatientInfo = documentEntry.getSourcePatientInfo();
                Patient sourcePatient = new Patient();
                if (sourcePatientId != null) {
                    sourcePatient.addIdentifier((new Identifier().setSystem("urn:oid:" + sourcePatientId.getAssigningAuthority().getUniversalId()).setValue(sourcePatientId.getId())).setUse(IdentifierUse.OFFICIAL));
                }
                if (sourcePatientInfo != null) {
                    sourcePatient.setBirthDateElement(transformToDate(sourcePatientInfo.getDateOfBirth()));
                    String gender = sourcePatientInfo.getGender();
                    if (gender != null) {
                        switch(gender) {
                            case "F":
                                sourcePatient.setGender(Enumerations.AdministrativeGender.FEMALE);
                                break;
                            case "M":
                                sourcePatient.setGender(Enumerations.AdministrativeGender.MALE);
                                break;
                            case "U":
                                sourcePatient.setGender(Enumerations.AdministrativeGender.UNKNOWN);
                                break;
                            case "A":
                                sourcePatient.setGender(Enumerations.AdministrativeGender.OTHER);
                                break;
                        }
                    }
                    ListIterator<Name> names = sourcePatientInfo.getNames();
                    while (names.hasNext()) {
                        Name name = names.next();
                        sourcePatient.addName(transform(name));
                    }
                    ListIterator<Address> addresses = sourcePatientInfo.getAddresses();
                    while (addresses.hasNext()) {
                        Address address = addresses.next();
                        if (address != null)
                            sourcePatient.addAddress(transform(address));
                    }
                }
                if (sourcePatientId != null || sourcePatientInfo != null) {
                    context.getSourcePatientInfo().setResource(sourcePatient);
                }
            }
        }
    } else {
        processError(input);
    }
    return list;
}
Also used : DocumentReferenceRelatesToComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent) DocumentReferenceContextComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContextComponent) Address(org.openehealth.ipf.commons.ihe.xds.core.metadata.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Attachment(org.hl7.fhir.r4.model.Attachment) PatientInfo(org.openehealth.ipf.commons.ihe.xds.core.metadata.PatientInfo) Name(org.openehealth.ipf.commons.ihe.xds.core.metadata.Name) Association(org.openehealth.ipf.commons.ihe.xds.core.metadata.Association) Identifier(org.hl7.fhir.r4.model.Identifier) ReferenceId(org.openehealth.ipf.commons.ihe.xds.core.metadata.ReferenceId) DocumentEntry(org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntry) ArrayList(java.util.ArrayList) List(java.util.List) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Period(org.hl7.fhir.r4.model.Period) Patient(org.hl7.fhir.r4.model.Patient) Identifiable(org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable) Practitioner(org.hl7.fhir.r4.model.Practitioner) AssociationType(org.openehealth.ipf.commons.ihe.xds.core.metadata.AssociationType) Author(org.openehealth.ipf.commons.ihe.xds.core.metadata.Author) Person(org.openehealth.ipf.commons.ihe.xds.core.metadata.Person) DocumentReferenceContentComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 ArrayList (java.util.ArrayList)23 Test (org.testng.annotations.Test)19 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)17 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)16 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)16 Reference (org.hl7.fhir.r4.model.Reference)15 HashMap (java.util.HashMap)11 Document (com.ibm.cloud.cloudant.v1.model.Document)10 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Observation (org.hl7.fhir.r4.model.Observation)8 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)7 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)7 MockResponse (okhttp3.mockwebserver.MockResponse)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 Coding (org.hl7.fhir.r4.model.Coding)7 Resource (org.hl7.fhir.r4.model.Resource)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)6