use of org.apache.nifi.controller.StandardSnippet in project nifi by apache.
the class StandardSnippetDAO method updateSnippetComponents.
@Override
public Snippet updateSnippetComponents(final SnippetDTO snippetDTO) {
// verify the action
verifyUpdateSnippetComponent(snippetDTO);
// find the snippet in question
final StandardSnippet snippet = locateSnippet(snippetDTO.getId());
// if the group is changing move it
if (snippetDTO.getParentGroupId() != null && !snippet.getParentGroupId().equals(snippetDTO.getParentGroupId())) {
final ProcessGroup currentProcessGroup = flowController.getGroup(snippet.getParentGroupId());
if (currentProcessGroup == null) {
throw new IllegalArgumentException("The current process group could not be found.");
}
final ProcessGroup newProcessGroup = flowController.getGroup(snippetDTO.getParentGroupId());
if (newProcessGroup == null) {
throw new IllegalArgumentException("The new process group could not be found.");
}
// move the snippet
currentProcessGroup.move(snippet, newProcessGroup);
// update its parent group id
snippet.setParentGroupId(snippetDTO.getParentGroupId());
}
return snippet;
}
use of org.apache.nifi.controller.StandardSnippet in project nifi by apache.
the class StandardSnippetDAO method dropSnippet.
@Override
public void dropSnippet(String snippetId) {
// drop the snippet itself
final StandardSnippet snippet = locateSnippet(snippetId);
flowController.getSnippetManager().removeSnippet(snippet);
}
use of org.apache.nifi.controller.StandardSnippet in project nifi by apache.
the class StandardSnippetDAO method createSnippet.
@Override
public Snippet createSnippet(final SnippetDTO snippetDTO) {
// create the snippet request
final StandardSnippet snippet = new StandardSnippet();
snippet.setId(snippetDTO.getId());
snippet.setParentGroupId(snippetDTO.getParentGroupId());
snippet.addProcessors(mapDtoToRevision(snippetDTO.getProcessors()));
snippet.addProcessGroups(mapDtoToRevision(snippetDTO.getProcessGroups()));
snippet.addRemoteProcessGroups(mapDtoToRevision(snippetDTO.getRemoteProcessGroups()));
snippet.addInputPorts(mapDtoToRevision(snippetDTO.getInputPorts()));
snippet.addOutputPorts(mapDtoToRevision(snippetDTO.getOutputPorts()));
snippet.addConnections(mapDtoToRevision(snippetDTO.getConnections()));
snippet.addLabels(mapDtoToRevision(snippetDTO.getLabels()));
snippet.addFunnels(mapDtoToRevision(snippetDTO.getFunnels()));
// ensure this snippet isn't empty
if (snippet.isEmpty()) {
throw new IllegalArgumentException("Cannot create an empty snippet.");
}
// ensure the parent group exist
final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
if (processGroup == null) {
throw new IllegalArgumentException("The specified parent process group could not be found.");
}
// store the snippet
flowController.getSnippetManager().addSnippet(snippet);
return snippet;
}
use of org.apache.nifi.controller.StandardSnippet in project nifi by apache.
the class StandardSnippetDeserializer method deserialize.
public static StandardSnippet deserialize(final InputStream inStream) {
try {
JAXBContext context = JAXBContext.newInstance(StandardSnippet.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
XMLStreamReader xsr = XmlUtils.createSafeReader(inStream);
JAXBElement<StandardSnippet> snippetElement = unmarshaller.unmarshal(xsr, StandardSnippet.class);
return snippetElement.getValue();
} catch (final JAXBException | XMLStreamException e) {
throw new FlowSerializationException(e);
}
}
Aggregations