Signing

Allow anyone to view and sign documents

553 views August 2, 2017 October 9, 2017 1

[Testmethod]
public async Task If_you_do_not_specify_a_subject_then_anyone_is_allowed_to_view_and_sign_the_document()
{
   sdsdocument uploadedDocument = await UploadDocument();
   createrequestrequest request = GetCreateRequest(uploadedDocument);

   // Let's not specify a subject
   //request.request[0].task[0].subject = GetSubject();
   createrequestresponse response;
   using (var client = new DocumentEndPointClient())
   {
   response = client.createRequest(request);
   }

   String signHereUrl =
   String.Format("https://preprod.signicat.com/std/docaction/demo?request_id={0}&task_id={1}", response.requestid[0],request.request[0].task[0].id);
   Console.WriteLine(signHereUrl);
   Assert.IsNotNull(response);
   Assert.IsNull(response.artifact);
   Assert.IsNotNull(response.requestid);
    }

    private async Task<sdsdocument> UploadDocument()
{
var httpClientHandler = new HttpClientHandler { Credentials = new NetworkCredential("demo", "Bond007") };
using (var client = new HttpClient(httpClientHandler))
{
	HttpContent content = new ByteArrayContent(File.ReadAllBytes("demo_avtale.pdf"));
	content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
	HttpResponseMessage response = await client.PostAsync("https://preprod.signicat.com/doc/demo/sds", content);
	string documentId = await response.Content.ReadAsStringAsync();
	return new sdsdocument
	{
		id = "doc_1",
		refsdsid = documentId,
		description = "Terms and conditions"
		};
	}
    }

private createrequestrequest GetCreateRequest(sdsdocument documentInSds)
{
	var request = new createrequestrequest
	{
		password = "Bond007",
		service = "demo",
		request = new request[]
		{
			new request
				{
					clientreference = "cliref1",
                        language = "da",
                        profile = "demo",
                        document = new document[]
                        {
                            documentInSds
                        },
                        task = new task[]
                        {
                            new task
                            {
                                id = "task_1", // Any identifier you'd like
                                subjectref = "subj_1", // Any identifier you'd like
                                documentaction = new documentaction[]
                                {
                                     new documentaction
                                     {
                                         type = documentactiontype.sign, // Sign or View
                                         documentref = "doc_1" // Any identifier you'd like
                                     }
                                },
                                signature = new signature[]
                                {
                                    new signature
                                    {
                                        method = new string[]
                                        {
                                            // The name of the signature method(s)
                                            "nemid-sign"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
		};
	return request;
}
package com.signicat.signature;

import com.signicat.document.v2.*;
import org.apache.http.client.fluent.Executor;
import org.apache.http.entity.ContentType;
import org.junit.Assert;
import org.junit.Test;

import javax.xml.ws.Service;
import java.io.File;
import java.io.IOException;

public class UploadAndCreateRequest {

	@Test
	public void if_you_do_not_specify_a_subject_then_anyone_is_allowed_to_view_and_sign_the_document()
			throws Exception {
		SdsDocument uploadedDocument = uploadDocument();
		CreateRequestRequest request = getCreateRequest(uploadedDocument);

		Service documentService = new DocumentService();
		DocumentEndPoint client = documentService.getPort(DocumentEndPoint.class);
		CreateRequestResponse response = client.createRequest(request);

		String signHereUrl =
				String.format("https://preprod.signicat.com/std/docaction/demo?request_id=%s&task_id=%s",
						response.getRequestId().get(0), request.getRequest().get(0).getTask().get(0).getId());
		System.out.println(signHereUrl);
		Assert.assertNotNull(response);
		Assert.assertNull(response.getArtifact());
		Assert.assertNotNull(response.getRequestId());
	}

	private SdsDocument uploadDocument() throws IOException {
		org.apache.http.client.fluent.Request request = org.apache.http.client.fluent.Request
				.Post("https://preprod.signicat.com/doc/demo/sds")
				.bodyFile(new File("src/test/resources/demo_avtale.pdf"), ContentType.create("application/pdf"));
		String documentId = Executor.newInstance()
				.auth("demo", "Bond007")
				.execute(request)
				.returnContent().asString();

		SdsDocument sdsDocument = new SdsDocument();
		sdsDocument.setId("doc_1");
		sdsDocument.setRefSdsId(documentId);
		sdsDocument.setDescription("Terms and conditions");
		return sdsDocument;
	}


	private CreateRequestRequest getCreateRequest(SdsDocument documentInSds) {
		CreateRequestRequest createRequestRequest = new CreateRequestRequest();
		createRequestRequest.setService("demo");
		createRequestRequest.setPassword("Bond007");

		Request request = new Request();
		request.setClientReference("cliref1");
		request.setLanguage("da");
		request.setProfile("demo");

		request.getDocument().add(documentInSds);

		Task task = new Task();
		task.setId("task_1"); // Any identifier you'd like
		task.setSubjectRef("subj_1"); // Any identifier you'd like
		task.setBundle(false);

		DocumentAction documentAction = new DocumentAction();
		documentAction.setType(DocumentActionType.SIGN); // Sign or View
		documentAction.setDocumentRef("doc_1"); // Any identifier you'd like
		task.getDocumentAction().add(documentAction);

		Signature signature = new Signature();
		signature.getMethod().add("nemid-sign"); // The name of the signature method(s)
		task.getSignature().add(signature);

		request.getTask().add(task);

		createRequestRequest.getRequest().add(request);
		return createRequestRequest;
	}
}

Was this helpful?