Search in sources :

Example 1 with FeedImporter

use of com.thinkbiganalytics.feedmgr.service.feed.importing.FeedImporter in project kylo by Teradata.

the class AdminController method uploadFeed.

/**
 * This is used for quick import via a script.  The UI uses the AdminControllerV2 class
 */
@POST
@Path(IMPORT_FEED)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Imports a feed zip file.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the feed metadata.", response = ImportFeed.class), @ApiResponse(code = 500, message = "There was a problem importing the feed.", response = RestResponseStatus.class) })
public Response uploadFeed(@NotNull @FormDataParam("file") InputStream fileInputStream, @NotNull @FormDataParam("file") FormDataContentDisposition fileMetaData, @FormDataParam("overwrite") @DefaultValue("false") boolean overwrite, @FormDataParam("overwriteFeedTemplate") @DefaultValue("false") boolean overwriteFeedTemplate, @FormDataParam("categorySystemName") String categorySystemName, @FormDataParam("importConnectingReusableFlow") @DefaultValue("NOT_SET") ImportTemplateOptions.IMPORT_CONNECTING_FLOW importConnectingFlow, @FormDataParam("templateProperties") @DefaultValue("") String templateProperties, @FormDataParam("feedProperties") @DefaultValue("") String feedProperties) throws Exception {
    ImportFeedOptions options = new ImportFeedOptions();
    String uploadKey = uploadProgressService.newUpload();
    options.setUploadKey(uploadKey);
    options.findImportComponentOption(ImportComponent.FEED_DATA).setOverwrite(overwrite);
    options.findImportComponentOption(ImportComponent.FEED_DATA).setUserAcknowledged(true);
    options.findImportComponentOption(ImportComponent.FEED_DATA).setShouldImport(true);
    options.findImportComponentOption(ImportComponent.REUSABLE_TEMPLATE).setShouldImport(importConnectingFlow.equals(ImportTemplateOptions.IMPORT_CONNECTING_FLOW.YES));
    options.findImportComponentOption(ImportComponent.REUSABLE_TEMPLATE).setUserAcknowledged(!importConnectingFlow.equals(ImportTemplateOptions.IMPORT_CONNECTING_FLOW.NOT_SET));
    options.findImportComponentOption(ImportComponent.REUSABLE_TEMPLATE).setOverwrite(importConnectingFlow.equals(ImportTemplateOptions.IMPORT_CONNECTING_FLOW.YES) && overwriteFeedTemplate);
    options.findImportComponentOption(ImportComponent.NIFI_TEMPLATE).setOverwrite(overwriteFeedTemplate);
    options.findImportComponentOption(ImportComponent.NIFI_TEMPLATE).setUserAcknowledged(true);
    options.findImportComponentOption(ImportComponent.NIFI_TEMPLATE).setShouldImport(true);
    options.findImportComponentOption(ImportComponent.NIFI_TEMPLATE).setContinueIfExists(!overwriteFeedTemplate);
    options.findImportComponentOption(ImportComponent.TEMPLATE_DATA).setOverwrite(overwriteFeedTemplate);
    options.findImportComponentOption(ImportComponent.TEMPLATE_DATA).setUserAcknowledged(true);
    options.findImportComponentOption(ImportComponent.TEMPLATE_DATA).setShouldImport(true);
    options.findImportComponentOption(ImportComponent.TEMPLATE_DATA).setContinueIfExists(!overwriteFeedTemplate);
    options.setCategorySystemName(categorySystemName);
    if (StringUtils.isNotBlank(templateProperties)) {
        List<ImportProperty> properties = ObjectMapperSerializer.deserialize(templateProperties, new TypeReference<List<ImportProperty>>() {
        });
        options.findImportComponentOption(ImportComponent.TEMPLATE_DATA).setProperties(properties);
    }
    if (StringUtils.isNotBlank(feedProperties)) {
        List<ImportProperty> properties = ObjectMapperSerializer.deserialize(feedProperties, new TypeReference<List<ImportProperty>>() {
        });
        options.findImportComponentOption(ImportComponent.FEED_DATA).setProperties(properties);
    }
    byte[] content = ImportUtil.streamToByteArray(fileInputStream);
    FeedImporter feedImporter = feedImporterFactory.apply(fileMetaData.getFileName(), content, options);
    ImportFeed importFeed = feedImporter.validateAndImport();
    return Response.ok(importFeed).build();
}
Also used : FeedImporter(com.thinkbiganalytics.feedmgr.service.feed.importing.FeedImporter) ImportProperty(com.thinkbiganalytics.feedmgr.rest.model.ImportProperty) ImportFeedOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportFeedOptions) List(java.util.List) ImportFeed(com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with FeedImporter

use of com.thinkbiganalytics.feedmgr.service.feed.importing.FeedImporter in project kylo by Teradata.

the class AdminControllerV2 method uploadFeed.

@POST
@Path(IMPORT_FEED)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Imports a feed zip file.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the feed metadata.", response = ImportFeed.class), @ApiResponse(code = 500, message = "There was a problem importing the feed.", response = RestResponseStatus.class) })
public Response uploadFeed(@NotNull @FormDataParam("file") InputStream fileInputStream, @NotNull @FormDataParam("file") FormDataContentDisposition fileMetaData, @NotNull @FormDataParam("uploadKey") String uploadKey, @FormDataParam("categorySystemName") String categorySystemName, @FormDataParam("disableFeedUponImport") @DefaultValue("false") boolean disableFeedUponImport, @FormDataParam("importComponents") String importComponents) throws Exception {
    ImportFeedOptions options = new ImportFeedOptions();
    options.setUploadKey(uploadKey);
    options.setDisableUponImport(disableFeedUponImport);
    ImportFeed importFeed = null;
    options.setCategorySystemName(categorySystemName);
    boolean overwriteFeed = true;
    boolean overwriteTemplate = true;
    uploadProgressService.newUpload(uploadKey);
    FeedImporter feedImporter = null;
    if (importComponents == null) {
        byte[] content = ImportUtil.streamToByteArray(fileInputStream);
        feedImporter = feedImporterFactory.apply(fileMetaData.getFileName(), content, options);
        importFeed = feedImporter.validate();
        importFeed.setSuccess(false);
    } else {
        options.setImportComponentOptions(ObjectMapperSerializer.deserialize(importComponents, new TypeReference<Set<ImportComponentOption>>() {
        }));
        byte[] content = ImportUtil.streamToByteArray(fileInputStream);
        feedImporter = feedImporterFactory.apply(fileMetaData.getFileName(), content, options);
        importFeed = feedImporter.validateAndImport();
    }
    uploadProgressService.removeUpload(uploadKey);
    return Response.ok(importFeed).build();
}
Also used : FeedImporter(com.thinkbiganalytics.feedmgr.service.feed.importing.FeedImporter) ImportFeedOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportFeedOptions) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ImportFeed(com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ImportFeedOptions (com.thinkbiganalytics.feedmgr.rest.model.ImportFeedOptions)2 FeedImporter (com.thinkbiganalytics.feedmgr.service.feed.importing.FeedImporter)2 ImportFeed (com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ImportComponentOption (com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)1 ImportProperty (com.thinkbiganalytics.feedmgr.rest.model.ImportProperty)1 List (java.util.List)1