org.apache.nifi.web.api.dto.PortDTO Java Examples

The following examples show how to use org.apache.nifi.web.api.dto.PortDTO. 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: StandardRemoteProcessGroup.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a set of ports into a set of remote process group ports.
 *
 * @param ports to convert
 * @return descriptors of ports
 */
private Set<RemoteProcessGroupPortDescriptor> convertRemotePort(final Set<PortDTO> ports) {
    Set<RemoteProcessGroupPortDescriptor> remotePorts = null;
    if (ports != null) {
        remotePorts = new LinkedHashSet<>(ports.size());
        for (final PortDTO port : ports) {
            final StandardRemoteProcessGroupPortDescriptor descriptor = new StandardRemoteProcessGroupPortDescriptor();
            final ScheduledState scheduledState = ScheduledState.valueOf(port.getState());
            descriptor.setId(generatePortId(port.getId()));
            descriptor.setTargetId(port.getId());
            descriptor.setName(port.getName());
            descriptor.setComments(port.getComments());
            descriptor.setTargetRunning(ScheduledState.RUNNING.equals(scheduledState));
            remotePorts.add(descriptor);
        }
    }
    return remotePorts;
}
 
Example #2
Source File: StandardRemoteProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a set of ports into a set of remote process group ports.
 *
 * @param ports to convert
 * @return descriptors of ports
 */
private Set<RemoteProcessGroupPortDescriptor> convertRemotePort(final Set<PortDTO> ports) {
    Set<RemoteProcessGroupPortDescriptor> remotePorts = null;
    if (ports != null) {
        remotePorts = new LinkedHashSet<>(ports.size());
        for (final PortDTO port : ports) {
            final StandardRemoteProcessGroupPortDescriptor descriptor = new StandardRemoteProcessGroupPortDescriptor();
            final ScheduledState scheduledState = ScheduledState.valueOf(port.getState());
            descriptor.setId(port.getId());
            descriptor.setName(port.getName());
            descriptor.setComments(port.getComments());
            descriptor.setTargetRunning(ScheduledState.RUNNING.equals(scheduledState));
            remotePorts.add(descriptor);
        }
    }
    return remotePorts;
}
 
Example #3
Source File: PortEntityMerger.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static void mergeDtos(final PortDTO clientDto, final Map<NodeIdentifier, PortDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }

    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();

    for (final Map.Entry<NodeIdentifier, PortDTO> nodeEntry : dtoMap.entrySet()) {
        final PortDTO nodePort = nodeEntry.getValue();

        // merge the validation errors if authorized
        if (nodePort != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodePort.getValidationErrors());
        }
    }

    // set the merged the validation errors
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
 
Example #4
Source File: FlowController.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public PortDTO updateOutputPort(final String parentGroupId, final PortDTO dto) {
    final ProcessGroup parentGroup = lookupGroup(parentGroupId);
    final Port port = parentGroup.getOutputPort(dto.getId());
    if (port == null) {
        throw new IllegalStateException("No Output Port with ID " + dto.getId() + " is known as a child of ProcessGroup with ID " + parentGroupId);
    }

    final String name = dto.getName();
    if (name != null) {
        port.setName(name);
    }

    if (dto.getPosition() != null) {
        port.setPosition(toPosition(dto.getPosition()));
    }

    return createDTO(port);
}
 
Example #5
Source File: FlowController.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public PortDTO updateInputPort(final String parentGroupId, final PortDTO dto) {
    final ProcessGroup parentGroup = lookupGroup(parentGroupId);
    final Port port = parentGroup.getInputPort(dto.getId());
    if (port == null) {
        throw new IllegalStateException("No Input Port with ID " + dto.getId() + " is known as a child of ProcessGroup with ID " + parentGroupId);
    }

    final String name = dto.getName();
    if (dto.getPosition() != null) {
        port.setPosition(toPosition(dto.getPosition()));
    }

    if (name != null) {
        port.setName(name);
    }

    return createDTO(port);
}
 
Example #6
Source File: AbstractPortDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private List<String> validateProposedConfiguration(final Port port, final PortDTO portDTO) {
    List<String> validationErrors = new ArrayList<>();

    if (isNotNull(portDTO.getName()) && portDTO.getName().trim().isEmpty()) {
        validationErrors.add("The name of the port must be specified.");
    }
    if (isNotNull(portDTO.getConcurrentlySchedulableTaskCount()) && portDTO.getConcurrentlySchedulableTaskCount() <= 0) {
        validationErrors.add("Concurrent tasks must be a positive integer.");
    }

    // Although StandardProcessGroup.addIn/OutputPort has the similar validation,
    // this validation is necessary to prevent a port becomes public with an existing port name.
    if (port instanceof PublicPort) {
        final String portName = isNotNull(portDTO.getName()) ? portDTO.getName() : port.getName();
        // If there is any port with the same name, but different identifier, throw an error.
        if (getPublicPorts().stream()
            .anyMatch(p -> portName.equals(p.getName()) && !port.getIdentifier().equals(p.getIdentifier()))) {
            throw new IllegalStateException("Public port name must be unique throughout the flow.");
        }
    }

    return validationErrors;
}
 
Example #7
Source File: PortEntityMerger.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static void mergeDtos(final PortDTO clientDto, final Map<NodeIdentifier, PortDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }

    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();

    for (final Map.Entry<NodeIdentifier, PortDTO> nodeEntry : dtoMap.entrySet()) {
        final PortDTO nodePort = nodeEntry.getValue();

        // merge the validation errors if authorized
        if (nodePort != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodePort.getValidationErrors());
        }
    }

    // set the merged the validation errors
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
 
Example #8
Source File: ITOutputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(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 PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

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

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

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

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example #9
Source File: FlowFromDOMFactory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public static PortDTO getPort(final Element element) {
    final PortDTO portDTO = new PortDTO();
    portDTO.setId(getString(element, "id"));
    portDTO.setPosition(getPosition(DomUtils.getChild(element, "position")));
    portDTO.setName(getString(element, "name"));
    portDTO.setComments(getString(element, "comments"));
    final ScheduledState scheduledState = getScheduledState(element);
    portDTO.setState(scheduledState.toString());

    final List<Element> maxTasksElements = getChildrenByTagName(element, "maxConcurrentTasks");
    if (!maxTasksElements.isEmpty()) {
        portDTO.setConcurrentlySchedulableTaskCount(Integer.parseInt(maxTasksElements.get(0).getTextContent()));
    }

    final List<Element> userAccessControls = getChildrenByTagName(element, "userAccessControl");
    if (userAccessControls != null && !userAccessControls.isEmpty()) {
        final Set<String> users = new HashSet<>();
        portDTO.setUserAccessControl(users);
        for (final Element userElement : userAccessControls) {
            users.add(userElement.getTextContent());
        }
    }

    final List<Element> groupAccessControls = getChildrenByTagName(element, "groupAccessControl");
    if (groupAccessControls != null && !groupAccessControls.isEmpty()) {
        final Set<String> groups = new HashSet<>();
        portDTO.setGroupAccessControl(groups);
        for (final Element groupElement : groupAccessControls) {
            groups.add(groupElement.getTextContent());
        }
    }

    return portDTO;
}
 
Example #10
Source File: ITOutputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private PortEntity createOutputPort(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/output-ports";

    final String updatedName = name + count++;

    // create the output port
    PortDTO outputPort = new PortDTO();
    outputPort.setName(updatedName);

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

    // create the entity body
    PortEntity entity = new PortEntity();
    entity.setRevision(revision);
    entity.setComponent(outputPort);

    // 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(PortEntity.class);

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

    // get the output port
    return entity;
}
 
Example #11
Source File: ITOutputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(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 PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

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

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example #12
Source File: FlowParser.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the ports that are direct children of the given element.
 *
 * @param element the element containing ports
 * @param type the type of port to find (inputPort or outputPort)
 * @return a list of PortDTOs representing the found ports
 */
private List<PortDTO> getPorts(final Element element, final String type) {
    final List<PortDTO> ports = new ArrayList<>();

    // add input ports
    final List<Element> portNodeList = getChildrenByTagName(element, type);
    for (final Element portElement : portNodeList) {
        final PortDTO portDTO = FlowFromDOMFactory.getPort(portElement);
        portDTO.setType(type);
        ports.add(portDTO);
    }

    return  ports;
}
 
Example #13
Source File: ITInputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private PortEntity createInputPort(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/input-ports";

    final String updatedName = name + count++;

    // create the input port
    PortDTO inputPort = new PortDTO();
    inputPort.setName(updatedName);

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

    // create the entity body
    PortEntity entity = new PortEntity();
    entity.setRevision(revision);
    entity.setComponent(inputPort);

    // 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(PortEntity.class);

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

    // get the input port
    return entity;
}
 
Example #14
Source File: ITInputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(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 PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

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

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example #15
Source File: ITInputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(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 PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

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

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

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

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example #16
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
public PortEntity createInputPort(final String name, final String groupId) throws NiFiClientException, IOException {
    final PortDTO component = new PortDTO();
    component.setName(name);
    component.setParentGroupId(groupId);

    final PortEntity inputPortEntity = new PortEntity();
    inputPortEntity.setRevision(createNewRevision());
    inputPortEntity.setComponent(component);

    return nifiClient.getInputPortClient().createInputPort(groupId, inputPortEntity);
}
 
Example #17
Source File: StandardNiFiServiceFacade.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public PortEntity updateInputPort(final Revision revision, final PortDTO inputPortDTO) {
    final Port inputPortNode = inputPortDAO.getPort(inputPortDTO.getId());
    final RevisionUpdate<PortDTO> snapshot = updateComponent(revision,
            inputPortNode,
            () -> inputPortDAO.updatePort(inputPortDTO),
            port -> dtoFactory.createPortDto(port));

    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(inputPortNode);
    final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getInputPortStatus(inputPortNode.getIdentifier()));
    final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(inputPortNode.getIdentifier()));
    final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
    return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
}
 
Example #18
Source File: StandardFlowServiceTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void assertEquals(PortDTO expected, PortDTO actual) {
    if (expected == null && actual == null) {
        return;
    }

    Assert.assertEquals(expected.getId(), actual.getId());
    Assert.assertEquals(expected.getName(), actual.getName());
    Assert.assertEquals(expected.getParentGroupId(), actual.getParentGroupId());
}
 
Example #19
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private PortDTO createDTO(final Port port) {
    if (port == null) {
        return null;
    }

    final PortDTO dto = new PortDTO();
    dto.setId(port.getIdentifier());
    dto.setPosition(new PositionDTO(port.getPosition().getX(), port.getPosition().getY()));
    dto.setName(port.getName());
    dto.setParentGroupId(port.getProcessGroup().getIdentifier());

    return dto;
}
 
Example #20
Source File: PortSchemaFunction.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Override
public PortSchema apply(PortDTO portDTO) {
    Map<String, Object> map = new HashMap<>();
    map.put(ID_KEY, portDTO.getId());
    map.put(NAME_KEY, portDTO.getName());
    return new PortSchema(map, wrapperName);
}
 
Example #21
Source File: PortSchemaFunctionTest.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    testId = UUID.nameUUIDFromBytes("testId".getBytes(StandardCharsets.UTF_8)).toString();
    testName = "testName";
    testWrapperName = "testWrapperName";
    portDTO = new PortDTO();
    portDTO.setId(testId);
    portDTO.setName(testName);
    portSchemaFunction = new PortSchemaFunction(testWrapperName);
}
 
Example #22
Source File: JerseyOutputPortClient.java    From nifi with Apache License 2.0 5 votes vote down vote up
private PortEntity createStateEntity(final PortEntity entity, final String state) {
    final PortDTO component = new PortDTO();
    component.setId(entity.getComponent().getId());
    component.setParentGroupId(entity.getComponent().getParentGroupId());
    component.setState(state);

    final PortEntity stateEntity = new PortEntity();
    stateEntity.setId(entity.getId());
    stateEntity.setRevision(entity.getRevision());
    stateEntity.setComponent(component);

    return stateEntity;
}
 
Example #23
Source File: JerseyInputPortClient.java    From nifi with Apache License 2.0 5 votes vote down vote up
private PortEntity createStateEntity(final PortEntity entity, final String state) {
    final PortDTO component = new PortDTO();
    component.setId(entity.getComponent().getId());
    component.setParentGroupId(entity.getComponent().getParentGroupId());
    component.setState(state);

    final PortEntity stateEntity = new PortEntity();
    stateEntity.setId(entity.getId());
    stateEntity.setRevision(entity.getRevision());
    stateEntity.setComponent(component);

    return stateEntity;
}
 
Example #24
Source File: ITOutputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(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 PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

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

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

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

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example #25
Source File: ITInputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
private PortEntity createInputPort(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/input-ports";

    final String updatedName = name + count++;

    // create the input port
    PortDTO inputPort = new PortDTO();
    inputPort.setName(updatedName);

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

    // create the entity body
    PortEntity entity = new PortEntity();
    entity.setRevision(revision);
    entity.setComponent(inputPort);

    // 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(PortEntity.class);

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

    // get the input port
    return entity;
}
 
Example #26
Source File: StandardInputPortDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Port createPort(String groupId, PortDTO portDTO) {
    if (isNotNull(portDTO.getParentGroupId()) && !flowController.getFlowManager().areGroupsSame(groupId, portDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the InputPort is being added.");
    }

    // ensure the name has been specified
    if (portDTO.getName() == null) {
        throw new IllegalArgumentException("Port name must be specified.");
    }

    // get the desired group
    ProcessGroup group = locateProcessGroup(flowController, groupId);

    // determine if this is the root group
    Port port;
    if (group.getParent() == null || Boolean.TRUE.equals(portDTO.getAllowRemoteAccess())) {
        port = flowController.getFlowManager().createPublicInputPort(portDTO.getId(), portDTO.getName());
    } else {
        port = flowController.getFlowManager().createLocalInputPort(portDTO.getId(), portDTO.getName());
    }

    // Unique public port check among all groups.
    if (port instanceof PublicPort) {
        verifyPublicPortUniqueness(port.getIdentifier(), port.getName());
    }

    // ensure we can perform the update before we add the port to the flow
    verifyUpdate(port, portDTO);

    // configure
    if (portDTO.getPosition() != null) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    port.setComments(portDTO.getComments());

    // add the port
    group.addInputPort(port);
    return port;
}
 
Example #27
Source File: StandardOutputPortDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Port createPort(String groupId, PortDTO portDTO) {
    if (isNotNull(portDTO.getParentGroupId()) && !flowController.getFlowManager().areGroupsSame(groupId, portDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the OutputPort is being added.");
    }

    // ensure the name has been specified
    if (portDTO.getName() == null) {
        throw new IllegalArgumentException("Port name must be specified.");
    }

    // get the desired group
    ProcessGroup group = locateProcessGroup(flowController, groupId);

    // determine if this is the root group
    Port port;
    if (group.getParent() == null || Boolean.TRUE.equals(portDTO.getAllowRemoteAccess())) {
        port = flowController.getFlowManager().createPublicOutputPort(portDTO.getId(), portDTO.getName());
    } else {
        port = flowController.getFlowManager().createLocalOutputPort(portDTO.getId(), portDTO.getName());
    }

    // Unique public port check among all groups.
    if (port instanceof PublicPort) {
        verifyPublicPortUniqueness(port.getIdentifier(), port.getName());
    }

    // ensure we can perform the update before we add the port to the flow
    verifyUpdate(port, portDTO);

    // configure
    if (portDTO.getPosition() != null) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    port.setComments(portDTO.getComments());

    // add the port
    group.addOutputPort(port);
    return port;
}
 
Example #28
Source File: ITOutputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(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 PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

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

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example #29
Source File: ITInputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(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 PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

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

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

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

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example #30
Source File: ITInputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(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 PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

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

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}