private CollectionSummaryInfo adaptCollectionToCollectionSummaryInfo(Collection collection) { CollectionSummaryInfo summaryInfo = new CollectionSummaryInfo(); summaryInfo.setCode(collection.getCode()); summaryInfo.setName(collection.getName()); summaryInfo.setCurator(collection.getOwner().getUserName()); summaryInfo.setStartDate(collection.getStartDate()); summaryInfo.setEndDate(collection.getEndDate()); summaryInfo.setCollectionCreationDate(collection.getCreatedAt()); // TODO to fetch from collection log try { summaryInfo.setTotalCount( collectionLogService.countTotalDownloadedItemsForCollection(collection.getId())); } catch (Exception e) { logger.warn("Error in fetch count from collection log.", e); summaryInfo.setTotalCount(collection.getCount()); } summaryInfo.setStatus(collection.getStatus().getStatus()); // TODO summaryInfo.setCreatedAt(collection.getCreatedAt()); summaryInfo.setLanguage(collection.getLangFilters()); summaryInfo.setKeywords(collection.getTrack()); summaryInfo.setGeo(collection.getGeo()); summaryInfo.setLabelCount(taggerService.getLabelCount(collection.getId())); summaryInfo.setPubliclyListed(collection.isPubliclyListed()); summaryInfo.setProvider(collection.getProvider().toString()); return summaryInfo; }
@Override @Transactional(readOnly = false) public Collection stop(Long collectionId, Long userId) throws Exception { Collection collection = collectionRepository.findById(collectionId); // Follwoing 2 lines added by koushik for downloadCount bug Collection c = this.statusByCollection(collection, userId); collection.setCount(c.getCount()); Collection updateCollection = stopAidrFetcher(collection, userId); CollectionLog collectionLog = new CollectionLog(collection); collectionLog.setUpdatedBy(userId); collectionLogRepository.save(collectionLog); return updateCollection; }
private Collection updateStatusCollection( String jsonResponse, Collection collection, Long accountId) throws Exception { ObjectMapper objectMapper = JacksonWrapper.getObjectMapper(); FetcheResponseDTO response = objectMapper.readValue(jsonResponse, FetcheResponseDTO.class); if (response != null) { // MEGHNA: moved setting collection count to top of the method // to avoid individual status blocks setting collection count below if (response.getCollectionCount() != null && !response.getCollectionCount().equals(collection.getCount())) { collection.setCount(response.getCollectionCount()); String lastDocument = response.getLastDocument(); collection.setLastExecutionTime(response.getLastExecutionTime()); if (lastDocument != null) collection.setLastDocument(lastDocument); collectionRepository.update(collection); } collection.setSourceOutage(response.isSourceOutage()); if (!CollectionStatus.getByStatus(response.getStatusCode()).equals(collection.getStatus())) { CollectionStatus prevStatus = collection.getStatus(); collection.setStatus(CollectionStatus.getByStatus(response.getStatusCode())); switch (CollectionStatus.getByStatus(response.getStatusCode())) { case NOT_FOUND: // case STOPPED: collection.setStatus(CollectionStatus.NOT_RUNNING); // Add collectionCount in collectionLog if it was not recorded. if (collection.getStartDate() != null && ((collection.getEndDate() != null && collection.getStartDate().after(collection.getEndDate())) || collection.getEndDate() == null)) { if (collectionLogRepository.countLogsStartedInInterval( collection.getId(), collection.getStartDate(), new Date()) == 0) { CollectionLog collectionLog = new CollectionLog(collection); collectionLog.setEndDate(new Date()); collectionLog.setUpdatedBy(accountId); collectionLogRepository.save(collectionLog); } } case RUNNING_WARNING: if (prevStatus == CollectionStatus.INITIALIZING) { collection = collectionRepository.start(collection.getId()); break; } case WARNING: collectionRepository.update(collection); break; case RUNNING: collection = collectionRepository.start(collection.getId()); break; case FATAL_ERROR: // collection = collectionRepository.stop(collection.getId()); logger.warn("Fatal error, stopping collection " + collection.getId()); if (prevStatus != CollectionStatus.FATAL_ERROR || prevStatus != CollectionStatus.NOT_RUNNING || prevStatus != CollectionStatus.STOPPED) this.stopFatalError(collection.getId(), accountId); break; case EXCEPTION: logger.warn( "Rejected Thread Execution Exception, restarting collection " + collection.getId()); if (prevStatus != CollectionStatus.EXCEPTION) { this.stopFatalError(collection.getId(), accountId); this.start(collection.getId()); } break; default: break; } } } return collection; }