@Override public String getUrlFromDocumentView(DocumentView docView) { DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<String>(); items.add(getPrefix()); IdRef docRef = docLoc.getIdRef(); if (docRef == null) { return null; } items.add(docRef.toString()); String uri = Joiner.on("/").join(items); return URIUtils.addParametersToURIQuery(uri, docView.getParameters()); } return null; }
@Override public String getUrlFromDocumentView(DocumentView docView) { DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(docLoc.getServerName()); IdRef docRef = docLoc.getIdRef(); if (docRef == null) { return null; } items.add(docRef.toString()); String viewId = docView.getViewId(); if (viewId != null) { items.add(viewId); } String uri = String.join("/", items); return URIUtils.addParametersToURIQuery(uri, docView.getParameters()); } return null; }
@Override public Resource getResource(Serializable object, Map<String, Object> context) { if (object instanceof DocumentModel) { DocumentModel doc = (DocumentModel) object; String localName = doc.getRepositoryName() + '/' + doc.getId(); return new QNameResourceImpl(namespace, localName); } else if (object instanceof DocumentLocation) { DocumentLocation docLoc = (DocumentLocation) object; String localName = docLoc.getServerName() + '/' + docLoc.getIdRef().toString(); return new QNameResourceImpl(namespace, localName); } else { throw new IllegalArgumentException(String.format("cannot build resource for '%s'", object)); } }
@Override protected void doWork() { ElasticSearchIndexing esi = Framework.getService(ElasticSearchIndexing.class); openSystemSession(); int bucketSize = Math.min(documentCount, getBucketSize()); List<String> ids = new ArrayList<>(bucketSize); for (DocumentLocation doc : getDocuments()) { ids.add(doc.getIdRef().value); if ((ids.size() % bucketSize) == 0) { esi.indexNonRecursive(getIndexingCommands(session, ids)); ids.clear(); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } } if (!ids.isEmpty()) { esi.indexNonRecursive(getIndexingCommands(session, ids)); ids.clear(); } if (syncAlias) { log.warn(String.format("Re-indexing job: %s completed.", getSchedulePath().getParentPath())); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); esa.syncSearchAndWriteAlias(esa.getIndexNameForRepository(repositoryName)); } }
protected static String getDocumentPart(String requestedURL) { String docPart = ""; DocumentViewCodecManager documentViewCodecManager = Framework.getService(DocumentViewCodecManager.class); DocumentView docView = documentViewCodecManager.getDocumentViewFromUrl(requestedURL, false, null); if (docView != null) { DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { String serverName = docLoc.getServerName(); if (serverName != null) { docPart += serverName; IdRef idRef = docLoc.getIdRef(); PathRef pathRef = docLoc.getPathRef(); if (idRef != null) { docPart += "/id/" + idRef; } else if (pathRef != null) { docPart += "/path" + pathRef; } } } } return docPart; }