use of com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate in project kylo by Teradata.
the class RegisteredTemplateService method getRegisteredTemplateForUpdate.
/**
* Return a registered template object that is populated for use with updating in Kylo
*
* @param registeredTemplateRequest the request to get a registered template
* @return a RegisteredTemplate object mapping either one already defined in Kylo, or a new template that maps to one in NiFi
*/
public RegisteredTemplate getRegisteredTemplateForUpdate(RegisteredTemplateRequest registeredTemplateRequest) {
if (registeredTemplateRequest.isTemplateEdit()) {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_TEMPLATES);
}
RegisteredTemplate registeredTemplate = null;
// attempt to find the template as a Service
RegisteredTemplateRequest serviceLevelRequest = new RegisteredTemplateRequest(registeredTemplateRequest);
// editing a feed will run as a service account
serviceLevelRequest.setFeedEdit(true);
RegisteredTemplate template = findRegisteredTemplate(serviceLevelRequest);
boolean canEdit = true;
if (template != null && StringUtils.isNotBlank(template.getId()) && registeredTemplateRequest.isTemplateEdit()) {
canEdit = checkTemplatePermission(template.getId(), TemplateAccessControl.EDIT_TEMPLATE);
}
if (canEdit) {
registeredTemplate = template;
if (registeredTemplate == null) {
registeredTemplate = nifiTemplateToRegisteredTemplate(registeredTemplateRequest.getNifiTemplateId());
}
if (registeredTemplate == null) {
// throw exception
} else {
if (StringUtils.isBlank(registeredTemplate.getId()) && template != null && StringUtils.isNotBlank(template.getId())) {
registeredTemplate.setId(template.getId());
}
Set<PortDTO> ports = null;
// fetch ports for this template
try {
if (registeredTemplate.getNifiTemplate() != null) {
ports = nifiRestClient.getPortsForTemplate(registeredTemplate.getNifiTemplate());
} else {
ports = nifiRestClient.getPortsForTemplate(registeredTemplate.getNifiTemplateId());
}
} catch (NifiComponentNotFoundException notFoundException) {
syncNiFiTemplateId(registeredTemplate);
ports = nifiRestClient.getPortsForTemplate(registeredTemplate.getNifiTemplateId());
}
if (ports == null) {
ports = new HashSet<>();
}
List<PortDTO> outputPorts = ports.stream().filter(portDTO -> portDTO != null && NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name().equalsIgnoreCase(portDTO.getType())).collect(Collectors.toList());
List<PortDTO> inputPorts = ports.stream().filter(portDTO -> portDTO != null && NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name().equalsIgnoreCase(portDTO.getType())).collect(Collectors.toList());
registeredTemplate.setReusableTemplate(inputPorts != null && !inputPorts.isEmpty());
List<ReusableTemplateConnectionInfo> reusableTemplateConnectionInfos = registeredTemplate.getReusableTemplateConnections();
List<ReusableTemplateConnectionInfo> updatedConnectionInfo = new ArrayList<>();
for (final PortDTO port : outputPorts) {
ReusableTemplateConnectionInfo reusableTemplateConnectionInfo = null;
if (reusableTemplateConnectionInfos != null && !reusableTemplateConnectionInfos.isEmpty()) {
reusableTemplateConnectionInfo = Iterables.tryFind(reusableTemplateConnectionInfos, reusableTemplateConnectionInfo1 -> reusableTemplateConnectionInfo1.getFeedOutputPortName().equalsIgnoreCase(port.getName())).orNull();
}
if (reusableTemplateConnectionInfo == null) {
reusableTemplateConnectionInfo = new ReusableTemplateConnectionInfo();
reusableTemplateConnectionInfo.setFeedOutputPortName(port.getName());
}
updatedConnectionInfo.add(reusableTemplateConnectionInfo);
}
registeredTemplate.setReusableTemplateConnections(updatedConnectionInfo);
registeredTemplate.initializeProcessors();
ensureRegisteredTemplateInputProcessors(registeredTemplate);
}
}
return registeredTemplate;
}
use of com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate in project kylo by Teradata.
the class RegisteredTemplateService method findRegisteredTemplateByName.
/**
* Find a template by the name
*
* @param templateName the name of the template
* @param principals list of principals required to access
* @return the RegisteredTemplate matching the passed in name or null if not found
*/
public RegisteredTemplate findRegisteredTemplateByName(final String templateName, TEMPLATE_TRANSFORMATION_TYPE transformationType, Principal... principals) {
return metadataAccess.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_TEMPLATES);
RegisteredTemplate registeredTemplate = null;
FeedManagerTemplate template = templateProvider.findByName(templateName);
if (template != null) {
registeredTemplate = templateModelTransform.getTransformationFunction(transformationType).apply(template);
}
return registeredTemplate;
}, principals);
}
use of com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate in project kylo by Teradata.
the class RegisteredTemplateService method findRegisteredTemplateByNiFiIdentifier.
/**
* Find a template by the nifi id
*
* @param nifiTemplateId the nifi id
* @param principals list of principals required to access
* @return the RegisteredTemplate matching the passed in nifiTemplateId, or null if not found
*/
private RegisteredTemplate findRegisteredTemplateByNiFiIdentifier(final String nifiTemplateId, TEMPLATE_TRANSFORMATION_TYPE transformationType, Principal... principals) {
if (StringUtils.isBlank(nifiTemplateId)) {
return null;
}
return metadataAccess.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_TEMPLATES);
RegisteredTemplate registeredTemplate = null;
FeedManagerTemplate template = templateProvider.findByNifiTemplateId(nifiTemplateId);
if (template != null) {
registeredTemplate = templateModelTransform.getTransformationFunction(transformationType).apply(template);
}
return registeredTemplate;
}, principals);
}
use of com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate in project kylo by Teradata.
the class RegisteredTemplateService method findRegisteredTemplateById.
/**
* Find a template by the Kylo Id
*
* @param templateId The Kylo {@link RegisteredTemplate#id}
* @param principals list or principals required to access
* @return the RegisteredTemplate matching the id or null if not found
*/
private RegisteredTemplate findRegisteredTemplateById(final String templateId, TEMPLATE_TRANSFORMATION_TYPE transformationType, Principal... principals) {
if (StringUtils.isBlank(templateId)) {
return null;
} else {
return metadataAccess.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_TEMPLATES);
RegisteredTemplate registeredTemplate = null;
FeedManagerTemplate.ID domainId = templateProvider.resolveId(templateId);
FeedManagerTemplate domainTemplate = templateProvider.findById(domainId);
if (domainTemplate != null) {
// transform it
registeredTemplate = templateModelTransform.getTransformationFunction(transformationType).apply(domainTemplate);
}
if (registeredTemplate != null) {
registeredTemplate.initializeProcessors();
ensureNifiTemplate(registeredTemplate);
}
return registeredTemplate;
}, principals);
}
}
use of com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate in project kylo by Teradata.
the class TemplateModelTransform method deserialize.
/**
* Deserialize the JSON of the template
*
* @param json the template json
* @param includeEncryptedProperties if true the encrypted properties will be returned. false will set the property values to ""
* @return the registered template
*/
private RegisteredTemplate deserialize(String json, boolean includeEncryptedProperties) {
RegisteredTemplate template = ObjectMapperSerializer.deserialize(json, RegisteredTemplate.class);
template.getProperties().stream().filter(nifiProperty -> nifiProperty.isSensitive()).forEach(nifiProperty -> {
if (!includeEncryptedProperties) {
nifiProperty.setValue("");
}
// else {
// String val = encryptionService.decrypt(nifiProperty.getValue());
// nifiProperty.setValue(val);
// }
});
return template;
}
Aggregations