Created
March 31, 2014 09:28
-
-
Save DemkaAge/9888687 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package ru.brbpm.lecm.server.version_comparator_service.logic; | |
import com.filenet.api.collection.PageIterator; | |
import com.filenet.api.collection.PropertyDescriptionList; | |
import com.filenet.api.collection.VersionableSet; | |
import com.filenet.api.core.*; | |
import com.filenet.api.exception.EngineRuntimeException; | |
import com.filenet.api.exception.ExceptionCode; | |
import com.filenet.api.meta.ClassDescription; | |
import com.filenet.api.util.Id; | |
import com.google.common.base.Preconditions; | |
import ru.brbpm.lecm.shared.dto.page.CeDocumentPage; | |
import ru.brbpm.lecm.shared.dto.version_comparator.CompareDocuments; | |
import ru.brbpm.lecm.shared.exceptions.ObjectNotFoundException; | |
import ru.brbpm.lecm.shared.filenet.ce.core.CeDocument; | |
import ru.brbpm.lecm.shared.filenet.ce.core.CeFactory; | |
import ru.brbpm.lecm.shared.filenet.ce.util.CeId; | |
import ru.brbpm.lecm.utils.server.LoggerUtils; | |
import ru.brbpm.lecm.utils.server.filenet.CeConvertUtil; | |
import ru.brbpm.lecm.utils.server.i18n.ExceptionUtils; | |
/** | |
* User: dshahovkin | |
* Date: 21.11.13 | |
* Time: 13:58 | |
*/ | |
public class VersionComparatorServiceHelper { | |
private static final LoggerUtils.MyLogger logger = LoggerUtils.getLogger(VersionComparatorServiceHelper.class); | |
private final Domain domain; | |
public VersionComparatorServiceHelper(Connection connection, String domainName) { | |
domain = Factory.Domain.getInstance(connection, domainName); | |
} | |
public CeDocumentPage getVersionsInit(String objectStoreName, CeId id) { | |
Preconditions.checkNotNull(objectStoreName, "Property 'objectStoreName' can't be null."); | |
Preconditions.checkNotNull(id, "Property 'id' can't be null."); | |
try { | |
ObjectStore objectStore = Factory.ObjectStore.getInstance(domain, objectStoreName); | |
Document document = Factory.Document.fetchInstance(objectStore, new Id(id.getId()), null); | |
VersionableSet versions = document.get_Versions(); | |
PageIterator pageIterator = versions.pageIterator(); | |
return getVersionsPage(pageIterator); | |
} catch (EngineRuntimeException e) { | |
if (e.getExceptionCode() == ExceptionCode.E_OBJECT_NOT_FOUND) { | |
throw ExceptionUtils.createException(ObjectNotFoundException.class, e, | |
ru.brbpm.lecm.shared.exceptions.ExceptionCode.GENERIC_OBJECT_NOT_FOUND, id.getId()); | |
} else { | |
throw e; | |
} | |
} | |
} | |
private CeDocumentPage getVersionsPage(PageIterator pageIterator) { | |
CeDocumentPage ceDocumentCePage = new CeDocumentPage(); | |
if (pageIterator.nextPage()) { | |
for (Object object : pageIterator.getCurrentPage()) { | |
Document document = (Document) object; | |
CeDocument dto = CeConvertUtil.createDto(CeFactory.CeDocument.createInstance(), document, false); | |
ceDocumentCePage.getData().add(dto); | |
} | |
if (pageIterator.nextPage()) { | |
ceDocumentCePage.setCheckPoint(pageIterator.getCurrentPageCheckpoint()); | |
} | |
} | |
return ceDocumentCePage; | |
} | |
public CeDocumentPage getVersionsNextPage(byte[] checkpoint) { | |
Preconditions.checkNotNull(checkpoint, "Property 'checkpoint' can't be null."); | |
PageIterator pageIterator = Factory.PageIterator.resumeInstance(domain.getConnection(), checkpoint); | |
return getVersionsPage(pageIterator); | |
} | |
public CompareDocuments getCompareDocuments(String objectStoreName, CeId leftDocumentId, CeId rightDocumentId) { | |
Preconditions.checkNotNull(objectStoreName, "Property 'objectStoreName' can't be null."); | |
Preconditions.checkNotNull(leftDocumentId, "Property 'leftDocumentId' can't be null."); | |
Preconditions.checkNotNull(rightDocumentId, "Property 'rightDocumentId' can't be null."); | |
CompareDocuments compareDocuments = new CompareDocuments(); | |
ObjectStore objectStore = Factory.ObjectStore.getInstance(domain, objectStoreName); | |
Document leftDocument = Factory.Document.fetchInstance(objectStore, new Id(leftDocumentId.getId()), null); | |
Document rightDocument = Factory.Document.fetchInstance(objectStore, new Id(rightDocumentId.getId()), null); | |
if (!leftDocument.getClassName().equalsIgnoreCase(rightDocument.getClassName())) { | |
throw ExceptionUtils.createLecmException(ru.brbpm.lecm.shared.exceptions.ExceptionCode | |
.VC_SERVICE_DIFFERENT_CLASSES); | |
} | |
ClassDescription classDescription = leftDocument.get_ClassDescription(); | |
PropertyDescriptionList propertyDescriptions = classDescription.get_PropertyDescriptions(); | |
// Set<String> propertyNameSet = new HashSet<String>(); | |
// for (Object propertyDescription : propertyDescriptions) { | |
// PropertyDescription description = (PropertyDescription) propertyDescription; | |
// if (description.getIsHidden() || description.getIsSystemGenerated() || description | |
// .getIsSystemGenerated()) { | |
// continue; | |
// } | |
// propertyNameSet.add(description.getSymbolicName()); | |
// } | |
CeConvertUtil.createDto(compareDocuments.getLeftDocument(), leftDocument, false); | |
CeConvertUtil.addContentElements(compareDocuments.getLeftDocument(), leftDocument, false); | |
//propertyNameSet.toArray(new String[propertyNameSet.size()])); | |
CeConvertUtil.createDto(compareDocuments.getRightDocument(), rightDocument, false); | |
CeConvertUtil.addContentElements(compareDocuments.getRightDocument(), rightDocument, false); | |
//propertyNameSet.toArray(new String[propertyNameSet.size()])); | |
CeConvertUtil.createCeClassDescription(compareDocuments.getClassDescription(), classDescription, false); | |
return compareDocuments; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment