Java Code Examples for org.apache.nifi.web.api.dto.ProcessGroupDTO#setName()

The following examples show how to use org.apache.nifi.web.api.dto.ProcessGroupDTO#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PGCreate.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException {

    final String processGroupName = getRequiredArg(properties, CommandOption.PG_NAME);

    final FlowClient flowClient = client.getFlowClient();
    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final String rootPgId = flowClient.getRootGroupId();

    final ProcessGroupDTO processGroupDTO = new ProcessGroupDTO();
    processGroupDTO.setParentGroupId(rootPgId);
    processGroupDTO.setName(processGroupName);

    final ProcessGroupEntity pgEntity = new ProcessGroupEntity();
    pgEntity.setComponent(processGroupDTO);
    pgEntity.setRevision(getInitialRevisionDTO());

    final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(
            rootPgId, pgEntity);

    return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
 
Example 2
Source File: ITProcessGroupAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put a process group.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutProcessGroup() throws Exception {
    final ProcessGroupEntity entity = getRandomProcessGroup(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final ProcessGroupDTO requestDto = new ProcessGroupDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);

    final ProcessGroupEntity requestEntity = new ProcessGroupEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final ClientResponse response = updateProcessGroup(helper.getWriteUser(), requestEntity);

    // ensure successful response
    assertEquals(200, response.getStatus());

    // get the response
    final ProcessGroupEntity responseEntity = response.getEntity(ProcessGroupEntity.class);

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example 3
Source File: ITProcessGroupAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put a process group.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutProcessGroup() throws Exception {
    final ProcessGroupEntity entity = getRandomProcessGroup(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final ProcessGroupDTO requestDto = new ProcessGroupDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);

    final ProcessGroupEntity requestEntity = new ProcessGroupEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final ClientResponse response = updateProcessGroup(helper.getNoneUser(), requestEntity);

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example 4
Source File: ITProcessGroupAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private ProcessGroupEntity createProcessGroup(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/process-groups";

    final String updatedName = name + count++;

    // create the process group
    ProcessGroupDTO processor = new ProcessGroupDTO();
    processor.setName(updatedName);

    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);

    // create the entity body
    ProcessGroupEntity entity = new ProcessGroupEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);

    // perform the request
    ClientResponse response = helper.getReadWriteUser().testPost(url, entity);

    // ensure the request is successful
    assertEquals(201, response.getStatus());

    // get the entity body
    entity = response.getEntity(ProcessGroupEntity.class);

    // verify creation
    processor = entity.getComponent();
    assertEquals(updatedName, processor.getName());

    // get the processor
    return entity;
}
 
Example 5
Source File: ITProcessGroupAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put a process group.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutProcessGroup() throws Exception {
    final ProcessGroupEntity entity = getRandomProcessGroup(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final ProcessGroupDTO requestDto = new ProcessGroupDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);

    final ProcessGroupEntity requestEntity = new ProcessGroupEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final Response response = updateProcessGroup(helper.getWriteUser(), requestEntity);

    // ensure successful response
    assertEquals(200, response.getStatus());

    // get the response
    final ProcessGroupEntity responseEntity = response.readEntity(ProcessGroupEntity.class);

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
    assertNull(responseEntity.getComponent());
}
 
Example 6
Source File: ITProcessGroupAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put a process group.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutProcessGroup() throws Exception {
    final ProcessGroupEntity entity = getRandomProcessGroup(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final ProcessGroupDTO requestDto = new ProcessGroupDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);

    final ProcessGroupEntity requestEntity = new ProcessGroupEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final Response response = updateProcessGroup(helper.getNoneUser(), requestEntity);

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example 7
Source File: ITProcessGroupAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
private ProcessGroupEntity createProcessGroup(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/process-groups";

    final String updatedName = name + count++;

    // create the process group
    ProcessGroupDTO processor = new ProcessGroupDTO();
    processor.setName(updatedName);

    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);

    // create the entity body
    ProcessGroupEntity entity = new ProcessGroupEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);

    // perform the request
    Response response = helper.getReadWriteUser().testPost(url, entity);

    // ensure the request is successful
    assertEquals(201, response.getStatus());

    // get the entity body
    entity = response.readEntity(ProcessGroupEntity.class);

    // verify creation
    processor = entity.getComponent();
    assertEquals(updatedName, processor.getName());

    // get the processor
    return entity;
}
 
Example 8
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
public ProcessGroupEntity createProcessGroup(final String name, final String parentGroupId) throws NiFiClientException, IOException {
    final ProcessGroupDTO component = new ProcessGroupDTO();
    component.setName(name);
    component.setParentGroupId(parentGroupId);

    final ProcessGroupEntity childGroupEntity = new ProcessGroupEntity();
    childGroupEntity.setRevision(createNewRevision());
    childGroupEntity.setComponent(component);

    final ProcessGroupEntity childGroup = nifiClient.getProcessGroupClient().createProcessGroup(parentGroupId, childGroupEntity);
    return childGroup;
}
 
Example 9
Source File: FlowFromDOMFactory.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public static ProcessGroupDTO getProcessGroup(final String parentId, final Element element, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) {
    final ProcessGroupDTO dto = new ProcessGroupDTO();
    final String groupId = getString(element, "id");
    dto.setId(groupId);
    dto.setParentGroupId(parentId);
    dto.setName(getString(element, "name"));
    dto.setPosition(getPosition(DomUtils.getChild(element, "position")));
    dto.setComments(getString(element, "comment"));

    final Set<ProcessorDTO> processors = new HashSet<>();
    final Set<ConnectionDTO> connections = new HashSet<>();
    final Set<FunnelDTO> funnels = new HashSet<>();
    final Set<PortDTO> inputPorts = new HashSet<>();
    final Set<PortDTO> outputPorts = new HashSet<>();
    final Set<LabelDTO> labels = new HashSet<>();
    final Set<ProcessGroupDTO> processGroups = new HashSet<>();
    final Set<RemoteProcessGroupDTO> remoteProcessGroups = new HashSet<>();

    NodeList nodeList = DomUtils.getChildNodesByTagName(element, "processor");
    for (int i = 0; i < nodeList.getLength(); i++) {
        processors.add(getProcessor((Element) nodeList.item(i), encryptor));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "funnel");
    for (int i = 0; i < nodeList.getLength(); i++) {
        funnels.add(getFunnel((Element) nodeList.item(i)));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "inputPort");
    for (int i = 0; i < nodeList.getLength(); i++) {
        inputPorts.add(getPort((Element) nodeList.item(i)));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "outputPort");
    for (int i = 0; i < nodeList.getLength(); i++) {
        outputPorts.add(getPort((Element) nodeList.item(i)));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "label");
    for (int i = 0; i < nodeList.getLength(); i++) {
        labels.add(getLabel((Element) nodeList.item(i)));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "processGroup");
    for (int i = 0; i < nodeList.getLength(); i++) {
        processGroups.add(getProcessGroup(groupId, (Element) nodeList.item(i), encryptor, encodingVersion));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "remoteProcessGroup");
    for (int i = 0; i < nodeList.getLength(); i++) {
        remoteProcessGroups.add(getRemoteProcessGroup((Element) nodeList.item(i), encryptor));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "connection");
    for (int i = 0; i < nodeList.getLength(); i++) {
        connections.add(getConnection((Element) nodeList.item(i)));
    }

    final FlowSnippetDTO groupContents = new FlowSnippetDTO();
    groupContents.setConnections(connections);
    groupContents.setFunnels(funnels);
    groupContents.setInputPorts(inputPorts);
    groupContents.setLabels(labels);
    groupContents.setOutputPorts(outputPorts);
    groupContents.setProcessGroups(processGroups);
    groupContents.setProcessors(processors);
    groupContents.setRemoteProcessGroups(remoteProcessGroups);

    dto.setContents(groupContents);
    return dto;
}
 
Example 10
Source File: FlowFromDOMFactory.java    From nifi with Apache License 2.0 4 votes vote down vote up
public static ProcessGroupDTO getProcessGroup(final String parentId, final Element element, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) {
    final ProcessGroupDTO dto = new ProcessGroupDTO();
    final String groupId = getString(element, "id");
    dto.setId(groupId);
    dto.setVersionedComponentId(getString(element, "versionedComponentId"));
    dto.setParentGroupId(parentId);
    dto.setName(getString(element, "name"));
    dto.setPosition(getPosition(DomUtils.getChild(element, "position")));
    dto.setComments(getString(element, "comment"));
    dto.setFlowfileConcurrency(getString(element, "flowfileConcurrency"));
    dto.setFlowfileOutboundPolicy(getString(element, "flowfileOutboundPolicy"));

    final Map<String, String> variables = new HashMap<>();
    final NodeList variableList = DomUtils.getChildNodesByTagName(element, "variable");
    for (int i = 0; i < variableList.getLength(); i++) {
        final Element variableElement = (Element) variableList.item(i);
        final String name = variableElement.getAttribute("name");
        final String value = variableElement.getAttribute("value");
        variables.put(name, value);
    }
    dto.setVariables(variables);

    final Element versionControlInfoElement = DomUtils.getChild(element, "versionControlInformation");
    dto.setVersionControlInformation(getVersionControlInformation(versionControlInfoElement));

    final String parameterContextId = getString(element, "parameterContextId");
    final ParameterContextReferenceEntity parameterContextReference = new ParameterContextReferenceEntity();
    parameterContextReference.setId(parameterContextId);
    dto.setParameterContext(parameterContextReference);

    final Set<ProcessorDTO> processors = new HashSet<>();
    final Set<ConnectionDTO> connections = new HashSet<>();
    final Set<FunnelDTO> funnels = new HashSet<>();
    final Set<PortDTO> inputPorts = new HashSet<>();
    final Set<PortDTO> outputPorts = new HashSet<>();
    final Set<LabelDTO> labels = new HashSet<>();
    final Set<ProcessGroupDTO> processGroups = new HashSet<>();
    final Set<RemoteProcessGroupDTO> remoteProcessGroups = new HashSet<>();

    NodeList nodeList = DomUtils.getChildNodesByTagName(element, "processor");
    for (int i = 0; i < nodeList.getLength(); i++) {
        processors.add(getProcessor((Element) nodeList.item(i), encryptor, encodingVersion));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "funnel");
    for (int i = 0; i < nodeList.getLength(); i++) {
        funnels.add(getFunnel((Element) nodeList.item(i)));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "inputPort");
    for (int i = 0; i < nodeList.getLength(); i++) {
        inputPorts.add(getPort((Element) nodeList.item(i)));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "outputPort");
    for (int i = 0; i < nodeList.getLength(); i++) {
        outputPorts.add(getPort((Element) nodeList.item(i)));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "label");
    for (int i = 0; i < nodeList.getLength(); i++) {
        labels.add(getLabel((Element) nodeList.item(i)));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "processGroup");
    for (int i = 0; i < nodeList.getLength(); i++) {
        processGroups.add(getProcessGroup(groupId, (Element) nodeList.item(i), encryptor, encodingVersion));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "remoteProcessGroup");
    for (int i = 0; i < nodeList.getLength(); i++) {
        remoteProcessGroups.add(getRemoteProcessGroup((Element) nodeList.item(i), encryptor));
    }

    nodeList = DomUtils.getChildNodesByTagName(element, "connection");
    for (int i = 0; i < nodeList.getLength(); i++) {
        connections.add(getConnection((Element) nodeList.item(i)));
    }

    final FlowSnippetDTO groupContents = new FlowSnippetDTO();
    groupContents.setConnections(connections);
    groupContents.setFunnels(funnels);
    groupContents.setInputPorts(inputPorts);
    groupContents.setLabels(labels);
    groupContents.setOutputPorts(outputPorts);
    groupContents.setProcessGroups(processGroups);
    groupContents.setProcessors(processors);
    groupContents.setRemoteProcessGroups(remoteProcessGroups);

    dto.setContents(groupContents);
    return dto;
}