Example usage for java.nio.file WatchEvent.Kind equals

List of usage examples for java.nio.file WatchEvent.Kind equals

Introduction

In this page you can find the example usage for java.nio.file WatchEvent.Kind equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:ddf.camel.component.catalog.content.ContentProducerDataAccessObject.java

public void createContentItem(FileSystemPersistenceProvider fileIdMap, ContentEndpoint endpoint,
        File ingestedFile, WatchEvent.Kind<Path> eventType, String mimeType, Map<String, Object> headers)
        throws SourceUnavailableException, IngestException {
    LOGGER.debug("Creating content item.");

    if (!eventType.equals(ENTRY_DELETE) && ingestedFile == null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Ingested File was null with eventType [{}]. Doing nothing.", eventType.name());
        }/* w w w.  j av  a 2  s . co  m*/
        return;
    }

    String refKey = (String) headers.get(Constants.STORE_REFERENCE_KEY);
    String safeKey = null;
    String id = null;

    // null if the file is being stored in the content store
    // not null if the file lives outside the content store (external reference)
    if (refKey != null) {
        // guards against impermissible filesystem characters
        safeKey = DigestUtils.sha1Hex(refKey);
        if (fileIdMap.loadAllKeys().contains(safeKey)) {
            id = String.valueOf(fileIdMap.loadFromPersistence(safeKey));
        } else if (!ENTRY_CREATE.equals(eventType)) {
            LOGGER.warn("Unable to look up id for {}, not performing {}", refKey, eventType.name());
            return;
        }
    }
    if (ENTRY_CREATE.equals(eventType)) {
        CreateStorageRequest createRequest = new CreateStorageRequestImpl(
                Collections.singletonList(
                        new ContentItemImpl(uuidGenerator.generateUuid(), Files.asByteSource(ingestedFile),
                                mimeType, ingestedFile.getName(), ingestedFile.length(), null)),
                getProperties(headers));

        CatalogFramework catalogFramework = endpoint.getComponent().getCatalogFramework();

        waitForAvailableSource(catalogFramework);

        CreateResponse createResponse = catalogFramework.create(createRequest);

        if (createResponse != null) {
            List<Metacard> createdMetacards = createResponse.getCreatedMetacards();

            if (safeKey != null) {
                fileIdMap.store(safeKey, createdMetacards.get(0).getId());
            }
            logIds(createdMetacards, "created");
        }
    } else if (ENTRY_MODIFY.equals(eventType)) {
        UpdateStorageRequest updateRequest = new UpdateStorageRequestImpl(
                Collections.singletonList(new ContentItemImpl(id, Files.asByteSource(ingestedFile), mimeType,
                        ingestedFile.getName(), 0, null)),
                getProperties(headers));

        UpdateResponse updateResponse = endpoint.getComponent().getCatalogFramework().update(updateRequest);
        if (updateResponse != null) {
            List<Update> updatedMetacards = updateResponse.getUpdatedMetacards();

            logIds(updatedMetacards.stream().map(Update::getNewMetacard).collect(Collectors.toList()),
                    "updated");
        }
    } else if (ENTRY_DELETE.equals(eventType)) {
        DeleteRequest deleteRequest = new DeleteRequestImpl(id);

        DeleteResponse deleteResponse = endpoint.getComponent().getCatalogFramework().delete(deleteRequest);
        if (deleteResponse != null) {
            List<Metacard> deletedMetacards = deleteResponse.getDeletedMetacards();

            if (safeKey != null) {
                fileIdMap.delete(safeKey);
            }
            logIds(deletedMetacards, "deleted");
        }
    }
}