Example usage for java.util SortedMap isEmpty

List of usage examples for java.util SortedMap isEmpty

Introduction

In this page you can find the example usage for java.util SortedMap isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:org.onebusaway.nyc.vehicle_tracking.impl.VehicleLocationSimulationServiceImpl.java

public void generateRunSim(Random random, SimulatorTask task, RunTripEntry runTrip, long serviceDate,
        int scheduleTime, int shiftStartTime, boolean reportsOperatorId, boolean reportsRunId,
        boolean allowRunTransitions, SortedMap<Double, Integer> scheduleDeviations, double locationSigma,
        AgencyAndId vehicleId) {//from   ww  w.  j  a va2  s .  c o  m

    /*
     * here we format the runId to have a run-route that looks similar to what
     * an operator would enter.
     */
    final String runNumber = runTrip.getRunNumber();
    String runRoute = runTrip.getRunRoute();

    if (StringUtils.equals(runRoute, "MISC")) {
        // runRoute = "0" + random.nextInt(9) + random.nextInt(9);
        runRoute = "000";
    } else if (runRoute.length() >= 5) {
        final String firstPart = runRoute.substring(1, 3);
        final String lastPart = runRoute.substring(3);
        runRoute = "0" + (random.nextBoolean() ? firstPart : lastPart);
    } else {
        final String firstPart = runRoute.substring(1, 3);
        runRoute = "0" + firstPart;
    }

    final String reportedRunId = RunTripEntry.createId(runRoute, runNumber);

    if (reportsRunId)
        _log.info("using reported runId=" + reportedRunId);

    String lastBlockId = null;

    final List<RunTripEntry> rtes = new ArrayList<RunTripEntry>();
    for (final RunTripEntry rte : _runService.getRunTripEntriesForRun(runTrip.getRunId())) {
        if (_calendarService.isLocalizedServiceIdActiveOnDate(rte.getTripEntry().getServiceId(),
                new Date(serviceDate)))
            rtes.add(rte);
    }

    if (rtes.isEmpty()) {
        _log.error("no active runTrips for service date=" + new Date(serviceDate));
    }
    // TODO necessary?
    Collections.sort(rtes, new RunTripComparator(serviceDate, _blockCalendarService));

    // String agencyId = runTrip.getTripEntry().getId().getAgencyId();

    CoordinatePoint lastLocation = null;
    final RunTripEntry lastRunTrip = rtes.get(rtes.size() - 1);
    final int firstTime = runTrip.getStartTime();
    final int lastTime = lastRunTrip.getStopTime();
    int runningLastTime = runTrip.getStopTime();
    int currRunIdx = rtes.indexOf(runTrip);

    // We could go by run trip entry sequence or perturbed schedule-time
    // evolution. The latter is chosen, for now.
    while (scheduleTime <= lastTime) {

        final NycTestInferredLocationRecord record = new NycTestInferredLocationRecord();

        final long unperturbedTimestamp = serviceDate + (scheduleTime + shiftStartTime) * 1000;

        if (scheduleTime >= runningLastTime) {
            if (currRunIdx == rtes.size() - 1)
                break;
            currRunIdx += 1;
            runTrip = rtes.get(currRunIdx);
            // runTrip = _runService.getNextEntry(runTrip);

            runningLastTime = runTrip.getStopTime();

            // FIXME saw weird run setups like this. are these in error?
            if (scheduleTime >= runningLastTime) {
                _log.error("runs are ordered oddly:" + rtes.get(currRunIdx - 1) + " -> " + runTrip);
                break;
            }
        }

        /*
         * this could mean that the run has ended. We could reassign the driver?
         * for now we'll terminate the simulation
         */
        if (runTrip == null)
            break;

        final TripEntry trip = runTrip.getTripEntry();

        final AgencyAndId tripId = trip.getId();

        record.setActualTripId(AgencyAndIdLibrary.convertToString(tripId));

        // TODO dsc changes for new block/run?
        String dsc = _destinationSignCodeService.getDestinationSignCodeForTripId(tripId);

        if (StringUtils.isEmpty(dsc))
            dsc = "0";

        // FIXME straighten these out...
        if (scheduleTime < runTrip.getStartTime()) {
            record.setActualPhase(EVehiclePhase.DEADHEAD_BEFORE.toString());
            dsc = "0";
        } else {
            record.setActualPhase(EVehiclePhase.IN_PROGRESS.toString());
        }

        int scheduleDeviation = 0;

        if (!scheduleDeviations.isEmpty()) {
            final double ratio = (scheduleTime - firstTime) / ((double) (lastTime - firstTime));
            scheduleDeviation = (int) InterpolationLibrary.interpolate(scheduleDeviations, ratio,
                    EOutOfRangeStrategy.LAST_VALUE);
        }

        final long perterbedTimestamp = unperturbedTimestamp + scheduleDeviation * 1000;

        /*
         * sample runTrips active 30 minutes from now. TODO make the time range
         * less arbitrary?
         */
        if (allowRunTransitions) {
            final RunTripEntry newRun = sampleNearbyRunTrips(runTrip, unperturbedTimestamp + 30 * 60 * 1000);

            if (newRun != null) {
                // FIXME can we get to this trip in 30, or whatever minutes?
                // FIXME what geometry do we follow to get there?

                /*
                 * we need to simulate the dsc/headsign: could set it to 0 the new
                 * trip the current trip ... TODO should this be a user option?
                 */
                record.setActualPhase(EVehiclePhase.DEADHEAD_BEFORE.toString());
                dsc = "0";

                runTrip = newRun;

                /*
                 * similarly, do we reset the reportedRunId? TODO also a user option?
                 */
                // reportedRunId = runTrip.getRun();

            }
        }

        // TODO when are there multiples and which do we choose when there are?
        final ScheduledBlockLocation blockLocation = _runService.getSchedBlockLocForRunTripEntryAndTime(runTrip,
                unperturbedTimestamp);

        if (blockLocation == null)
            break;

        final BlockEntry blockEntry = blockLocation.getActiveTrip().getBlockConfiguration().getBlock();

        _log.debug("sim blockLocation: " + blockLocation.toString());
        CoordinatePoint location = blockLocation.getLocation();

        record.setActualRunId(runTrip.getRunId());

        final String currentBlockId = AgencyAndIdLibrary.convertToString(blockEntry.getId());
        // if (_log.isDebugEnabled())
        if (lastBlockId != null && !StringUtils.equals(currentBlockId, lastBlockId)) {
            _log.info("changed blocks: " + lastBlockId + " -> " + currentBlockId);
        }
        record.setActualBlockId(currentBlockId);
        lastBlockId = currentBlockId;
        record.setActualDistanceAlongBlock(blockLocation.getDistanceAlongBlock());

        /*
         * during block changes we get a weird null location. this is a
         * "work-around"...
         */
        if (location == null) {
            location = lastLocation;
        } else {
            lastLocation = location;
        }
        final CoordinatePoint p = applyLocationNoise(location.getLat(), location.getLon(), locationSigma,
                random);

        record.setDsc(dsc);
        record.setLat(p.getLat());
        record.setLon(p.getLon());
        record.setTimestamp(perterbedTimestamp);
        record.setVehicleId(vehicleId);
        // TODO options for whether these are reported or not?
        if (reportsOperatorId)
            record.setOperatorId("0000");

        if (reportsRunId) {
            record.setReportedRunId(reportedRunId);
        }

        record.setActualServiceDate(serviceDate);

        final int actualScheduleTime = blockLocation.getScheduledTime();
        record.setActualScheduleTime(actualScheduleTime);

        record.setActualDsc(dsc);
        record.setActualBlockLat(location.getLat());
        record.setActualBlockLon(location.getLon());
        // TODO setActualStatus?

        task.addRecord(record);

        scheduleTime += 30 + random.nextGaussian() * 2;
    }

}

From source file:org.apache.accumulo.tserver.Tablet.java

/**
 * yet another constructor - this one allows us to avoid costly lookups into the Metadata table if we already know the files we need - as at split time
 *//*from   w w w.j  a va 2 s.c o  m*/
private Tablet(final TabletServer tabletServer, final Text location, final KeyExtent extent,
        final TabletResourceManager trm, final Configuration conf, final VolumeManager fs,
        final List<LogEntry> logEntries, final SortedMap<FileRef, DataFileValue> datafiles, String time,
        final TServerInstance lastLocation, Set<FileRef> scanFiles, long initFlushID, long initCompactID)
        throws IOException {
    Path locationPath;
    if (location.find(":") >= 0) {
        locationPath = new Path(location.toString());
    } else {
        locationPath = fs.getFullPath(FileType.TABLE, extent.getTableId().toString() + location.toString());
    }

    locationPath = DirectoryDecommissioner.checkTabletDirectory(tabletServer, fs, extent, locationPath);

    this.location = locationPath;
    this.lastLocation = lastLocation;
    this.tabletDirectory = location.toString();
    this.conf = conf;
    this.acuTableConf = tabletServer.getTableConfiguration(extent);

    this.fs = fs;
    this.extent = extent;
    this.tabletResources = trm;

    this.lastFlushID = initFlushID;
    this.lastCompactID = initCompactID;

    if (extent.isRootTablet()) {
        long rtime = Long.MIN_VALUE;
        for (FileRef ref : datafiles.keySet()) {
            Path path = ref.path();
            FileSystem ns = fs.getFileSystemByPath(path);
            FileSKVIterator reader = FileOperations.getInstance().openReader(path.toString(), true, ns,
                    ns.getConf(), tabletServer.getTableConfiguration(extent));
            long maxTime = -1;
            try {

                while (reader.hasTop()) {
                    maxTime = Math.max(maxTime, reader.getTopKey().getTimestamp());
                    reader.next();
                }

            } finally {
                reader.close();
            }

            if (maxTime > rtime) {
                time = TabletTime.LOGICAL_TIME_ID + "" + maxTime;
                rtime = maxTime;
            }
        }
    }
    if (time == null && datafiles.isEmpty() && extent.equals(RootTable.OLD_EXTENT)) {
        // recovery... old root tablet has no data, so time doesn't matter:
        time = TabletTime.LOGICAL_TIME_ID + "" + Long.MIN_VALUE;
    }

    this.tabletServer = tabletServer;
    this.logId = tabletServer.createLogId(extent);

    this.timer = new TabletStatsKeeper();

    setupDefaultSecurityLabels(extent);

    tabletMemory = new TabletMemory();
    tabletTime = TabletTime.getInstance(time);
    persistedTime = tabletTime.getTime();

    acuTableConf.addObserver(configObserver = new ConfigurationObserver() {

        private void reloadConstraints() {
            constraintChecker.set(new ConstraintChecker(acuTableConf));
        }

        @Override
        public void propertiesChanged() {
            reloadConstraints();

            try {
                setupDefaultSecurityLabels(extent);
            } catch (Exception e) {
                log.error("Failed to reload default security labels for extent: " + extent.toString());
            }
        }

        @Override
        public void propertyChanged(String prop) {
            if (prop.startsWith(Property.TABLE_CONSTRAINT_PREFIX.getKey()))
                reloadConstraints();
            else if (prop.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
                try {
                    log.info("Default security labels changed for extent: " + extent.toString());
                    setupDefaultSecurityLabels(extent);
                } catch (Exception e) {
                    log.error("Failed to reload default security labels for extent: " + extent.toString());
                }
            }

        }

        @Override
        public void sessionExpired() {
            log.debug("Session expired, no longer updating per table props...");
        }

    });

    acuTableConf.getNamespaceConfiguration().addObserver(configObserver);

    // Force a load of any per-table properties
    configObserver.propertiesChanged();

    if (!logEntries.isEmpty()) {
        log.info("Starting Write-Ahead Log recovery for " + this.extent);
        final long[] count = new long[2];
        final CommitSession commitSession = tabletMemory.getCommitSession();
        count[1] = Long.MIN_VALUE;
        try {
            Set<String> absPaths = new HashSet<String>();
            for (FileRef ref : datafiles.keySet())
                absPaths.add(ref.path().toString());

            tabletServer.recover(this.tabletServer.getFileSystem(), extent, acuTableConf, logEntries, absPaths,
                    new MutationReceiver() {
                        @Override
                        public void receive(Mutation m) {
                            // LogReader.printMutation(m);
                            Collection<ColumnUpdate> muts = m.getUpdates();
                            for (ColumnUpdate columnUpdate : muts) {
                                if (!columnUpdate.hasTimestamp()) {
                                    // if it is not a user set timestamp, it must have been set
                                    // by the system
                                    count[1] = Math.max(count[1], columnUpdate.getTimestamp());
                                }
                            }
                            tabletMemory.mutate(commitSession, Collections.singletonList(m));
                            count[0]++;
                        }
                    });

            if (count[1] != Long.MIN_VALUE) {
                tabletTime.useMaxTimeFromWALog(count[1]);
            }
            commitSession.updateMaxCommittedTime(tabletTime.getTime());

            if (count[0] == 0) {
                MetadataTableUtil.removeUnusedWALEntries(extent, logEntries, tabletServer.getLock());
                logEntries.clear();
            }

        } catch (Throwable t) {
            if (acuTableConf.getBoolean(Property.TABLE_FAILURES_IGNORE)) {
                log.warn("Error recovering from log files: ", t);
            } else {
                throw new RuntimeException(t);
            }
        }
        // make some closed references that represent the recovered logs
        currentLogs = new HashSet<DfsLogger>();
        for (LogEntry logEntry : logEntries) {
            for (String log : logEntry.logSet) {
                currentLogs.add(new DfsLogger(tabletServer.getServerConfig(), log));
            }
        }

        log.info("Write-Ahead Log recovery complete for " + this.extent + " (" + count[0]
                + " mutations applied, " + tabletMemory.getNumEntries() + " entries created)");
    }

    String contextName = acuTableConf.get(Property.TABLE_CLASSPATH);
    if (contextName != null && !contextName.equals("")) {
        // initialize context classloader, instead of possibly waiting for it to initialize for a scan
        // TODO this could hang, causing other tablets to fail to load - ACCUMULO-1292
        AccumuloVFSClassLoader.getContextManager().getClassLoader(contextName);
    }

    // do this last after tablet is completely setup because it
    // could cause major compaction to start
    datafileManager = new DatafileManager(datafiles);

    computeNumEntries();

    datafileManager.removeFilesAfterScan(scanFiles);

    // look for hints of a failure on the previous tablet server
    if (!logEntries.isEmpty() || needsMajorCompaction(MajorCompactionReason.NORMAL)) {
        // look for any temp files hanging around
        removeOldTemporaryFiles();
    }

    log.log(TLevel.TABLET_HIST, extent + " opened");
}

From source file:com.zimbra.cs.account.ProvUtil.java

private void displayAttrs(String op, boolean expandAll, boolean allAttrs,
        SortedMap<String, RightCommand.EffectiveAttr> attrs) {
    if (!allAttrs && attrs.isEmpty()) {
        return;//w w w  .  j av a2  s .c o  m
    }
    String format = "    %-50s %-30s\n";
    console.println();
    console.println("=========================");
    console.println(op + " attributes rights");
    console.println("=========================");
    if (allAttrs) {
        console.println("Can " + op + " all attributes");
    }
    if (!allAttrs || expandAll) {
        console.println("Can " + op + " the following attributes");
        console.println("--------------------------------");
        console.printf(format, "attribute", "default");
        console.printf(format, "----------------------------------------", "--------------------");
        for (RightCommand.EffectiveAttr ea : attrs.values()) {
            boolean first = true;
            if (ea.getDefault().isEmpty()) {
                console.printf(format, ea.getAttrName(), "");
            } else {
                for (String v : ea.getDefault()) {
                    if (first) {
                        console.printf(format, ea.getAttrName(), v);
                        first = false;
                    } else {
                        console.printf(format, "", v);
                    }
                }
            }
        }
    }
}

From source file:com.inqool.dcap.office.indexer.indexer.SolrBulkIndexer.java

private SolrInputDocument recursivelyIndex(final ModelTreeNode data) throws IOException {
    ZdoModel model;/*from  w w w  . ja  v a 2s.  com*/

    model = data.getModel();

    if (model == null) {
        return null;
    }

    //        if (!model.isIndexable()) {
    //            logger.debug("Resource: {} retrieved without indexable type.", uri);
    //            return null;
    //        }
    logger.debug("Resource: {} retrieved with indexable type.", store.removeTransactionFromUrl(model.getUrl()));

    if (!allowableTypes.contains(model.get(ZdoTerms.zdoType))) {
        return null;
    }

    if (!ZdoGroup.ZDO.name().equals(model.get(ZdoTerms.group))) {
        logger.info("Not indexing this document as it is not published.");
        return null;
    }

    final SolrInputDocument inputDoc = modelToSolrInputDoc(model);

    //        inputDoc.addField("datePublished", OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.UTC).format(DateTimeFormatter.ISO_DATE_TIME));
    String datePublished = model.get(ZdoTerms.datePublished);
    if (datePublished != null) { //If reindexing, we just read data about when it was originally published from Fedora
        inputDoc.addField("datePublished", datePublished);
    } else {
        datePublished = LocalDateTime.now().atZone(ZoneOffset.systemDefault())
                .withZoneSameInstant(ZoneOffset.UTC).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        inputDoc.addField("datePublished", datePublished); //solr needs UTC time
        ZdoModel patchmodel = new ZdoModel();
        patchmodel.setUrl(model.getUrl());
        patchmodel.add(ZdoTerms.datePublished, datePublished);
        store.patchMetadata(patchmodel);
    }
    //Get all children's uris, parse them recursively, and add them to result
    //If we are an almost-leaf node, also search for children bound on the original object
    String originalObjectUrl = model.get(ZdoTerms.kdrObject);
    if (!ZdoType.isBranchEndCategory(model.get(ZdoTerms.zdoType))) {
        for (ModelTreeNode child : data.getChildren()) {
            SolrInputDocument childDoc = recursivelyIndex(child);
            if (childDoc != null) {
                inputDoc.addChildDocument(childDoc);
            }
        }
    } else { //we are end branch category
        //Treat born digital documents differently as they don't have pages but whole PDF
        if (ZdoType.bornDigital.name().equals(model.get(ZdoTerms.zdoType))) {
            //Retrieve the usercopy - PDF
            String queryString = "SELECT ?userCopy ?thumb WHERE {\n"
                    + "?userCopy <http://purl.org/dc/terms/isPartOf> <" + originalObjectUrl + ">.\n"
                    + "?userCopy <" + ZdoTerms.zdoType.getURI() + "> \"" + ZdoType.binary.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n" + "?userCopy <"
                    + ZdoTerms.fileType.getURI() + "> \"" + ZdoFileType.userCopy.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n" + "}";
            QueryExecution queryExecution = QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT, queryString);
            ResultSet resultSet = queryExecution.execSelect();
            if (resultSet.hasNext()) {
                QuerySolution querySolution = resultSet.next();
                String userCopyUrl = querySolution.getResource("userCopy").getURI();
                inputDoc.addField("pdfId", store.getOnlyIdFromUrl(userCopyUrl));
            } else {
                throw new RuntimeException("Damn this pdf has no pdf or thumbnail.");
            }
        } else { //Other than born-digital branch end node
            //These are to sort pages based on their index
            SortedMap<Integer, String> imageMap = new TreeMap<>();
            SortedMap<Integer, String> thumbMap = new TreeMap<>();
            SortedMap<Integer, String> txtMap = new TreeMap<>();
            SortedMap<Integer, String> altoMap = new TreeMap<>();

            String videoUrl = null;

            //Retrieve image, thumbnail and ocr text info
            String queryString = "SELECT ?pageIndex ?userCopy ?ucMime ?thumb ?txt ?alto WHERE {\n" +
            //first find pages - children of the node
                    "?page <" + ZdoTerms.zdoType.getURI() + "> \"" + ZdoType.page.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n"
                    + "?page <http://purl.org/dc/terms/isPartOf> <" + originalObjectUrl + ">.\n" + "?page <"
                    + ZdoTerms.pageIndex.getURI() + "> ?pageIndex.\n" + "OPTIONAL {\n" +
                    //then children of those pages that are binary usercopy images
                    "?userCopy <http://purl.org/dc/terms/isPartOf> ?page.\n" + "?userCopy <"
                    + ZdoTerms.zdoType.getURI() + "> \"" + ZdoType.binary.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n" + "?userCopy <"
                    + ZdoTerms.fileType.getURI() + "> \"" + ZdoFileType.userCopy.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n" + "?userCopy <"
                    + ZdoTerms.mimeType.getURI() + "> ?ucMime.\n" + "}\nOPTIONAL {\n" +
                    //and their thumbnails
                    "?thumb <http://purl.org/dc/terms/isPartOf> ?page.\n" + "?thumb <"
                    + ZdoTerms.zdoType.getURI() + "> \"" + ZdoType.binary.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n" + "?thumb <"
                    + ZdoTerms.fileType.getURI() + "> \"" + ZdoFileType.thumb.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n" + "}\nOPTIONAL {\n" +
                    //and also children of those pages that are binary text
                    "?txt <http://purl.org/dc/terms/isPartOf> ?page.\n" + "?txt <" + ZdoTerms.zdoType.getURI()
                    + "> \"" + ZdoType.binary.name() + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n"
                    + "?txt <" + ZdoTerms.fileType.getURI() + "> \"" + ZdoFileType.txt.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n" + "}\nOPTIONAL {\n" +
                    //and also alto children with ocr text
                    "?alto <http://purl.org/dc/terms/isPartOf> ?page.\n" + "?alto <" + ZdoTerms.zdoType.getURI()
                    + "> \"" + ZdoType.binary.name() + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n"
                    + "?alto <" + ZdoTerms.fileType.getURI() + "> \"" + ZdoFileType.alto.name()
                    + "\"^^<http://www.w3.org/2001/XMLSchema#string>.\n" + "}\n}";
            QueryExecution queryExecution = QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT, queryString);
            ResultSet resultSet = queryExecution.execSelect();
            while (resultSet.hasNext()) {
                QuerySolution querySolution = resultSet.next();
                Integer pageIndex = Integer.valueOf(querySolution.getLiteral("pageIndex").getString());
                Resource userCopyResource = querySolution.getResource("userCopy");
                if (userCopyResource != null) {
                    String userCopyUrl = userCopyResource.getURI();
                    if (userCopyUrl != null) {
                        if ("video/mp4".equals(querySolution.getLiteral("ucMime").getString())) {
                            if (videoUrl != null) {
                                logger.error(
                                        "More than one video per document encountered. There can only be one.");
                            }
                            videoUrl = userCopyUrl;
                        } else {
                            imageMap.put(pageIndex, userCopyUrl);
                        }
                    }
                }
                Resource thumbnailResource = querySolution.getResource("thumb");
                if (thumbnailResource != null) {
                    String thumbUrl = thumbnailResource.getURI();
                    if (thumbUrl != null) {
                        thumbMap.put(pageIndex, thumbUrl);
                    }
                }
                Resource txtResource = querySolution.getResource("txt");
                if (txtResource != null) {
                    String txtUrl = txtResource.getURI();
                    if (txtUrl != null) {
                        txtMap.put(pageIndex, txtUrl);
                    }
                }
                Resource altoResource = querySolution.getResource("alto");
                if (altoResource != null) {
                    String altoUrl = altoResource.getURI();
                    if (altoUrl != null) {
                        altoMap.put(pageIndex, altoUrl);
                    }
                }
            }

            if (videoUrl != null) {
                inputDoc.addField("videoId", store.getOnlyIdFromUrl(videoUrl));
            }

            List<String> imageIds = new ArrayList<>();
            if (!imageMap.isEmpty()) {
                for (String userCopyUrl : imageMap.values()) {
                    imageIds.add(store.getOnlyIdFromUrl(userCopyUrl));
                }
                inputDoc.addField("imageIds", imageIds);
            }

            if (!thumbMap.isEmpty()) {
                List<String> thumbIds = new ArrayList<>();
                for (String thumbUrl : thumbMap.values()) {
                    thumbIds.add(store.getOnlyIdFromUrl(thumbUrl));
                }
                inputDoc.addField("thumbIds", thumbIds);
            }

            List<String> txtIds = new ArrayList<>();
            if (!txtMap.isEmpty()) {
                String fulltext = "";
                for (String txtUrl : txtMap.values()) {
                    txtIds.add(store.getOnlyIdFromUrl(txtUrl));
                    InputStream in = new URL(txtUrl).openStream();
                    StringWriter writer = new StringWriter();
                    IOUtils.copy(in, writer, "utf-8");
                    String text = writer.toString();
                    fulltext += text + " ";
                }
                inputDoc.addField("fullText", fulltext.trim());
            }

            List<String> altoIds = new ArrayList<>();
            if (!altoMap.isEmpty()) {
                for (String altoUrl : altoMap.values()) {
                    altoIds.add(store.getOnlyIdFromUrl(altoUrl));
                }
            }

            ZdoModel kdrObject = store.get(model.get(ZdoTerms.kdrObject));
            String origPdfUrl = kdrObject.get(ZdoTerms.pdfUrl);
            String origEpubUrl = kdrObject.get(ZdoTerms.epubUrl);
            ZdoModel patchModel = new ZdoModel(); //Used to add new pdf and epub data to Fedora
            patchModel.setUrl(model.get(ZdoTerms.kdrObject));
            if ("true".equals(model.get(ZdoTerms.allowPdfExport)) && !imageIds.isEmpty()) {
                if (origPdfUrl == null) {
                    String pdfId = UUID.randomUUID().toString();
                    patchModel.add(ZdoTerms.pdfUrl, store.createUrl(pdfId));
                    String orgId = model.get(ZdoTerms.organization);

                    String watermarkId = null;
                    if ("true".equals(model.get(ZdoTerms.watermark))) {
                        watermarkId = organizationSettingsAccess.fetchOrgWatermark(orgId);
                        if (watermarkId == null) {
                            watermarkId = portalSettingsAccess.fetchPortalSettings().getWatermarkId();
                        }
                    }

                    PdfCreatorDto pdfCreatorDto = new PdfCreatorDto(pdfId, imageIds, altoIds, watermarkId,
                            model.get(ZdoTerms.watermarkPosition));
                    Response response = ClientBuilder.newClient().target(IP_ENDPOINT + "pdf").request()
                            .post(Entity.json(pdfCreatorDto));
                    if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
                        throw new RuntimeException("Failed to call pdf creator in image processing war.");
                    }
                    inputDoc.addField("pdfId", pdfId);
                } else { //When reindexing, pdf already exists
                    inputDoc.addField("pdfId", store.getOnlyIdFromUrl(origPdfUrl));
                }
            }
            if ("true".equals(model.get(ZdoTerms.allowEpubExport)) && !txtIds.isEmpty()) {
                if (origEpubUrl == null) {
                    String epubId = UUID.randomUUID().toString();
                    patchModel.add(ZdoTerms.epubUrl, store.createUrl(epubId));
                    epubCreator.createBook(epubId, model.get(DCTerms.title), model.get(DCTerms.creator),
                            txtIds);
                    inputDoc.addField("epubId", epubId);
                } else {
                    inputDoc.addField("epubId", store.getOnlyIdFromUrl(origEpubUrl));
                }
            }
            store.patchMetadata(patchModel); //warning, this does not go to triplestore
        }
    }

    logger.debug("Executing update of: {}...", store.removeTransactionFromUrl(model.getUrl()));

    return inputDoc;
}