GroupDocsGists
10/24/2017 - 1:19 PM

Examples-GroupDocs.Annotation.Examples.Java-src-main-java-GroupDocs-Annotation-Examples-Java-DataStorage-addCollaborator.java

// For complete examples and data files, please go to https://github.com/groupdocs-annotation/GroupDocs.Annotation-for-Java
try {
	// Create instance of the annotation handler
	AnnotationConfig cfg = Utilities.getConfiguration();
	AnnotationImageHandler annotator = new AnnotationImageHandler(cfg);
	IUserDataHandler userRepository = annotator.getUserDataHandler();
	IDocumentDataHandler documentRepository = annotator.getDocumentDataHandler();
	// Create owner.
	User owner = userRepository.getUserByEmail("john@doe.com");
	if (owner == null) {
		final User user = new User();
		user.setFirstName("John");
		user.setLastName("Doe");
		user.setEmail("john@doe.com");
		userRepository.add(user);
		owner = userRepository.getUserByEmail("john@doe.com");
	}
	// Create document data object in storage
	Document document = documentRepository.getDocument(fileName);
	if (document != null && document.getOwnerId() != owner.getId()) {
		documentRepository.remove(document);
		document = null;
	}
	long documentId = document == null ? annotator.createDocument(fileName, DocumentType.Pdf, owner.getId())
			: document.getId();
	// Create reviewer.
	ReviewerInfo reviewerInfo = new ReviewerInfo();
	reviewerInfo.setPrimaryEmail("judy@doe.com");
	reviewerInfo.setFirstName("Judy");
	reviewerInfo.setLastName("Doe");
	reviewerInfo.setAccessRights(AnnotationReviewerRights.All);
	// Add collaborator to the document. If user with UserName equals to
	// reviewers PrimaryEmail is absent it will be created.
	SetCollaboratorsResult addCollaboratorResult = annotator.addCollaborator(documentId, reviewerInfo);
	System.out.println(addCollaboratorResult);
} catch (Exception e) {
	System.out.println("Exception: " + e.getMessage());
	e.printStackTrace();
}