use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class ImportTemplateArchive method importFeedTemplate.
@Nullable
private RegisteredTemplate importFeedTemplate(RegisteredTemplate existingTemplate) {
RegisteredTemplate template = null;
niFiTemplateImport = importIntoNiFi(this.importTemplate, this.importTemplateOptions);
ImportComponentOption registeredTemplateImport = this.importTemplateOptions.findImportComponentOption(ImportComponent.TEMPLATE_DATA);
if (existingTemplate != null) {
importTemplate.setTemplateId(existingTemplate.getId());
}
if (registeredTemplateImport.isShouldImport() && registeredTemplateImport.isValidForImport()) {
UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Importing feed template");
this.newTemplateInstance = create(niFiTemplateImport, statusMessage);
if (newTemplateInstance.isSuccess()) {
importTemplate.setSuccess(true);
RegisteredTemplate savedTemplate = registerTemplate(importTemplate, importTemplateOptions);
if (savedTemplate != null) {
template = savedTemplate;
}
} else {
importTemplate.setSuccess(false);
}
statusMessage.complete(importTemplate.isSuccess());
} else {
importTemplate.setSuccess(true);
}
return template;
}
use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class ValidateImportTemplatesArchive method validateRegisteredTemplate.
/**
* Validate the Registered Template is valid for importing
*/
private void validateRegisteredTemplate() {
ImportComponentOption registeredTemplateOption = this.importTemplateOptions.findImportComponentOption(ImportComponent.TEMPLATE_DATA);
// validate template
boolean validForImport = true;
if (!registeredTemplateOption.isUserAcknowledged()) {
this.importTemplate.setValid(false);
this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, "A template exists. Do you want to import it?");
}
if (registeredTemplateOption.isUserAcknowledged() && registeredTemplateOption.isShouldImport()) {
UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(this.importTemplateOptions.getUploadKey(), "Validating feed template for import");
RegisteredTemplate registeredTemplate = this.importTemplate.getTemplateToImport();
// validate unique
// 1 find if the template exists in the system running as a service account
RegisteredTemplate existingTemplate = registeredTemplateService.findRegisteredTemplate(new RegisteredTemplateRequest.Builder().templateName(registeredTemplate.getTemplateName()).isFeedEdit(true).build());
if (existingTemplate != null) {
if (this.importTemplateOptions.stopProcessingAlreadyExists(ImportComponent.TEMPLATE_DATA)) {
this.importTemplate.setValid(false);
String msg = "Unable to import the template " + registeredTemplate.getTemplateName() + " It is already registered.";
this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, msg);
statusMessage.update("Validation error: The template " + registeredTemplate.getTemplateName() + " is already registered", false);
} else {
// skip importing if user doesnt want it.
if (!registeredTemplateOption.isOverwrite()) {
validForImport = false;
}
statusMessage.complete(true);
}
registeredTemplate.setId(existingTemplate.getId());
// validate entity access
if (accessController.isEntityAccessControlled() && registeredTemplateOption.isOverwrite()) {
// requery as the currently logged in user
statusMessage = uploadProgressService.addUploadStatus(this.importTemplateOptions.getUploadKey(), "Validating template entity access");
existingTemplate = registeredTemplateService.findRegisteredTemplate(RegisteredTemplateRequest.requestByTemplateName(registeredTemplate.getTemplateName()));
// ensure the user can Edit this template
boolean valid = existingTemplate != null && existingTemplate.getAllowedActions().hasAction(TemplateAccessControl.EDIT_TEMPLATE.getSystemName());
if (!valid) {
this.importTemplate.setValid(false);
validForImport = false;
statusMessage.update("Access Denied: You do not have edit access for the template " + registeredTemplate.getTemplateName(), false);
this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, "Access Denied: You do not have edit access for the template ");
} else {
statusMessage.complete(valid);
}
}
} else {
// template doesnt exist.. it is new ensure the user is allowed to create templates
boolean editAccess = accessController.hasPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_TEMPLATES);
if (!editAccess) {
statusMessage.update("Access Denied: You are not allowed to create the template " + registeredTemplate.getTemplateName(), false);
this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, "Access Denied: You are not allowed to create the template ");
}
registeredTemplate.setId(null);
statusMessage.complete(editAccess);
}
validForImport &= !registeredTemplateOption.hasErrorMessages();
if (validForImport) {
boolean isValid = validateTemplateProperties();
if (this.importTemplate.isValid()) {
this.importTemplate.setValid(isValid);
}
validForImport &= isValid;
}
registeredTemplateOption.setValidForImport(validForImport);
}
this.uploadProgressService.completeSection(this.importTemplateOptions, ImportSection.Section.VALIDATE_REGISTERED_TEMPLATE);
}
use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class ValidateImportTemplatesArchive method validateReusableTemplate.
/**
* Validate any reusable templates as part of a zip file upload are valid for importing
*/
private void validateReusableTemplate() {
// validate the reusable template
if (this.importTemplate.hasConnectingReusableTemplate()) {
ImportComponentOption reusableTemplateOption = this.importTemplateOptions.findImportComponentOption(ImportComponent.REUSABLE_TEMPLATE);
UploadProgressMessage reusableTemplateStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Validating Reusable Template. ");
if (reusableTemplateOption.isShouldImport()) {
boolean validForImport = true;
// for each of the connecting template
for (String reusableTemplateXml : this.importTemplate.getNifiConnectingReusableTemplateXmls()) {
try {
String templateName = NifiTemplateParser.getTemplateName(reusableTemplateXml);
UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Validating Reusable Template. " + templateName);
TemplateDTO dto = nifiRestClient.getTemplateByName(templateName);
// if there is a match and it has not been acknowledged by the user to overwrite or not, error out
if (dto != null && !reusableTemplateOption.isUserAcknowledged()) {
// error out it exists
this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.REUSABLE_TEMPLATE, "A reusable template with the same name " + templateName + " exists.");
this.importTemplate.setValid(false);
statusMessage.update("Reusable template, " + templateName + ", already exists.", false);
validForImport = false;
} else if (dto != null && reusableTemplateOption.isUserAcknowledged() && !reusableTemplateOption.isOverwrite()) {
validForImport = false;
// user has asked to not import the template.
uploadProgressService.removeMessage(importTemplateOptions.getUploadKey(), statusMessage);
} else {
uploadProgressService.removeMessage(importTemplateOptions.getUploadKey(), statusMessage);
// statusMessage.update("Validated Reusable Template", true);
validForImport &= true;
}
} catch (Exception e) {
log.error("Error parsing template name from file {} ", fileName, e);
validForImport = false;
}
}
reusableTemplateOption.setValidForImport(validForImport);
reusableTemplateStatusMessage.update("Validated Reusable Templates ", !reusableTemplateOption.hasErrorMessages());
} else if (!reusableTemplateOption.isUserAcknowledged()) {
this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.REUSABLE_TEMPLATE, "The file " + this.importTemplate.getFileName() + " has a reusable template to import.");
this.importTemplate.setValid(false);
reusableTemplateStatusMessage.update("A reusable template was found. Additional input needed.", false);
} else {
reusableTemplateStatusMessage.update("Reusable template found in import, but it is not marked for importing", true);
}
}
this.uploadProgressService.completeSection(this.importTemplateOptions, ImportSection.Section.VALIDATE_REUSABLE_TEMPLATE);
}
use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class ImportUtil method addToImportOptionsSensitiveProperties.
public static void addToImportOptionsSensitiveProperties(ImportOptions importOptions, List<NifiProperty> sensitiveProperties, ImportComponent component) {
ImportComponentOption option = importOptions.findImportComponentOption(component);
if (option.getProperties().isEmpty()) {
option.setProperties(sensitiveProperties.stream().map(p -> new ImportProperty(p.getProcessorName(), p.getProcessorId(), p.getKey(), "", p.getProcessorType())).collect(Collectors.toList()));
} else {
// only add in those that are unique
Map<String, ImportProperty> propertyMap = option.getProperties().stream().collect(Collectors.toMap(p -> p.getProcessorNameTypeKey(), p -> p));
sensitiveProperties.stream().filter(nifiProperty -> !propertyMap.containsKey(nifiProperty.getProcessorNameTypeKey())).forEach(p -> {
option.getProperties().add(new ImportProperty(p.getProcessorName(), p.getProcessorId(), p.getKey(), "", p.getProcessorType()));
});
}
}
use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class ImportUtil method applyImportPropertiesToTemplate.
public static boolean applyImportPropertiesToTemplate(RegisteredTemplate template, ImportTemplate importTemplate, ImportComponent component) {
ImportComponentOption option = importTemplate.getImportOptions().findImportComponentOption(component);
if (!option.getProperties().isEmpty() && option.getProperties().stream().anyMatch(importProperty -> StringUtils.isBlank(importProperty.getPropertyValue()))) {
importTemplate.setSuccess(false);
importTemplate.setTemplateResults(new NifiProcessGroup());
String msg = "Unable to import Template. Additional properties to be supplied before importing.";
importTemplate.getTemplateResults().addError(NifiError.SEVERITY.WARN, msg, "");
option.getErrorMessages().add(msg);
return false;
} else {
template.getSensitiveProperties().forEach(nifiProperty -> {
ImportProperty userSuppliedValue = option.getProperties().stream().filter(importFeedProperty -> nifiProperty.getProcessorId().equalsIgnoreCase(importFeedProperty.getProcessorId()) && nifiProperty.getKey().equalsIgnoreCase(importFeedProperty.getPropertyKey())).findFirst().orElse(null);
// deal with nulls?
if (userSuppliedValue == null) {
// attempt to find it via the name
userSuppliedValue = option.getProperties().stream().filter(importFeedProperty -> nifiProperty.getProcessorName().equalsIgnoreCase(importFeedProperty.getProcessorName()) && nifiProperty.getKey().equalsIgnoreCase(importFeedProperty.getPropertyKey())).findFirst().orElse(null);
}
if (userSuppliedValue != null) {
nifiProperty.setValue(userSuppliedValue.getPropertyValue());
}
});
return true;
}
}
Aggregations