]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
787065b750e6fbfb9ae140cfaf5581ef65606040
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.export;
2
3 import java.util.Iterator;
4 import java.util.List;
5
6 import org.collectionspace.services.client.PoxPayloadIn;
7 import org.collectionspace.services.client.PoxPayloadOut;
8 import org.collectionspace.services.common.NuxeoBasedResource;
9 import org.collectionspace.services.common.ServiceMain;
10 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
11 import org.collectionspace.services.common.context.ServiceBindingUtils;
12 import org.collectionspace.services.common.context.ServiceContext;
13 import org.collectionspace.services.common.vocabulary.AuthorityResource;
14 import org.collectionspace.services.config.service.ServiceBindingType;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public class DocumentsByCsidIterator implements Iterator<PoxPayloadOut> {
19         private final Logger logger = LoggerFactory.getLogger(DocumentsByCsidIterator.class);
20
21   private NuxeoBasedResource resource;
22   private String vocabulary;
23   private ServiceContext<PoxPayloadIn, PoxPayloadOut> serviceContext;
24   private Iterator<String> csidIterator;
25   private boolean isAuthorityItem = false;
26
27   DocumentsByCsidIterator(
28     ServiceContext<PoxPayloadIn, PoxPayloadOut> serviceContext,
29     String docType,
30     String vocabulary,
31     List<String> csids) throws Exception {
32
33     TenantBindingConfigReaderImpl tenantBindingConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();
34     ServiceBindingType serviceBinding = tenantBindingConfigReader.getServiceBindingForDocType(serviceContext.getTenantId(), docType);
35     String serviceType = serviceBinding.getType();
36     String serviceName = serviceBinding.getName();
37
38     this.serviceContext = serviceContext;
39     this.csidIterator = csids.iterator();
40     this.isAuthorityItem = ServiceBindingUtils.SERVICE_TYPE_AUTHORITY.equals(serviceType);
41     this.vocabulary = vocabulary;
42
43     this.resource = isAuthorityItem
44       ? AuthorityResource.getResourceForItem(serviceContext.getResourceMap(), serviceContext.getTenantId(), docType)
45       : (NuxeoBasedResource) serviceContext.getResource(serviceName.toLowerCase());
46   }
47
48   @Override
49   public boolean hasNext() {
50     return csidIterator.hasNext();
51   }
52
53   @Override
54   public PoxPayloadOut next() {
55     String csid = csidIterator.next();
56
57     try {
58       return (isAuthorityItem
59         ? ((AuthorityResource<?, ?>) resource).getAuthorityItemWithExistingContext(serviceContext, vocabulary == null ? AuthorityResource.PARENT_WILDCARD : vocabulary, csid)
60         : resource.getWithParentCtx(serviceContext, csid));
61     }
62     catch (Exception e) {
63       logger.warn("Could not get document with csid " + csid, e);
64
65       return null;
66     }
67   }
68 }