use of org.apache.nifi.web.api.dto.action.HistoryDTO in project nifi by apache.
the class DtoFactory method createHistoryDto.
/**
* Creates a HistoryDTO from the specified History.
*
* @param history history
* @return dto
*/
public HistoryDTO createHistoryDto(final History history) {
final HistoryDTO historyDto = new HistoryDTO();
historyDto.setTotal(history.getTotal());
historyDto.setLastRefreshed(history.getLastRefreshed());
return historyDto;
}
use of org.apache.nifi.web.api.dto.action.HistoryDTO in project nifi by apache.
the class StandardNiFiServiceFacade method getActions.
@Override
public HistoryDTO getActions(final HistoryQueryDTO historyQueryDto) {
// extract the query criteria
final HistoryQuery historyQuery = new HistoryQuery();
historyQuery.setStartDate(historyQueryDto.getStartDate());
historyQuery.setEndDate(historyQueryDto.getEndDate());
historyQuery.setSourceId(historyQueryDto.getSourceId());
historyQuery.setUserIdentity(historyQueryDto.getUserIdentity());
historyQuery.setOffset(historyQueryDto.getOffset());
historyQuery.setCount(historyQueryDto.getCount());
historyQuery.setSortColumn(historyQueryDto.getSortColumn());
historyQuery.setSortOrder(historyQueryDto.getSortOrder());
// perform the query
final History history = auditService.getActions(historyQuery);
// only retain authorized actions
final HistoryDTO historyDto = dtoFactory.createHistoryDto(history);
if (history.getActions() != null) {
final List<ActionEntity> actionEntities = new ArrayList<>();
for (final Action action : history.getActions()) {
final AuthorizationResult result = authorizeAction(action);
actionEntities.add(entityFactory.createActionEntity(dtoFactory.createActionDto(action), Result.Approved.equals(result.getResult())));
}
historyDto.setActions(actionEntities);
}
// create the response
return historyDto;
}
use of org.apache.nifi.web.api.dto.action.HistoryDTO in project nifi by apache.
the class FlowResource method queryHistory.
// -------
// history
// -------
/**
* Queries the history of this Controller.
*
* @param offset The offset into the data. This parameter is required and is
* used in conjunction with count.
* @param count The number of rows that should be returned. This parameter
* is required and is used in conjunction with page.
* @param sortColumn The column to sort on. This parameter is optional. If
* not specified the results will be returned with the most recent first.
* @param sortOrder The sort order.
* @param startDate The start date/time for the query. The start date/time
* must be formatted as 'MM/dd/yyyy HH:mm:ss'. This parameter is optional
* and must be specified in the timezone of the server. The server's
* timezone can be determined by inspecting the result of a status or
* history request.
* @param endDate The end date/time for the query. The end date/time must be
* formatted as 'MM/dd/yyyy HH:mm:ss'. This parameter is optional and must
* be specified in the timezone of the server. The server's timezone can be
* determined by inspecting the result of a status or history request.
* @param userIdentity The user name of the user who's actions are being
* queried. This parameter is optional.
* @param sourceId The id of the source being queried (usually a processor
* id). This parameter is optional.
* @return A historyEntity.
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("history")
@ApiOperation(value = "Gets configuration history", notes = NON_GUARANTEED_ENDPOINT, response = HistoryEntity.class, authorizations = { @Authorization(value = "Read - /flow") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response queryHistory(@ApiParam(value = "The offset into the result set.", required = true) @QueryParam("offset") IntegerParameter offset, @ApiParam(value = "The number of actions to return.", required = true) @QueryParam("count") IntegerParameter count, @ApiParam(value = "The field to sort on.", required = false) @QueryParam("sortColumn") String sortColumn, @ApiParam(value = "The direction to sort.", required = false) @QueryParam("sortOrder") String sortOrder, @ApiParam(value = "Include actions after this date.", required = false) @QueryParam("startDate") DateTimeParameter startDate, @ApiParam(value = "Include actions before this date.", required = false) @QueryParam("endDate") DateTimeParameter endDate, @ApiParam(value = "Include actions performed by this user.", required = false) @QueryParam("userIdentity") String userIdentity, @ApiParam(value = "Include actions on this component.", required = false) @QueryParam("sourceId") String sourceId) {
authorizeFlow();
// ensure the page is specified
if (offset == null) {
throw new IllegalArgumentException("The desired offset must be specified.");
} else if (offset.getInteger() < 0) {
throw new IllegalArgumentException("The desired offset must be an integer value greater than or equal to 0.");
}
// ensure the row count is specified
if (count == null) {
throw new IllegalArgumentException("The desired row count must be specified.");
} else if (count.getInteger() < 1) {
throw new IllegalArgumentException("The desired row count must be an integer value greater than 0.");
}
// normalize the sort order
if (sortOrder != null) {
if (!sortOrder.equalsIgnoreCase("asc") && !sortOrder.equalsIgnoreCase("desc")) {
throw new IllegalArgumentException("The sort order must be 'asc' or 'desc'.");
}
}
// ensure the start and end dates are specified
if (endDate != null && startDate != null) {
if (endDate.getDateTime().before(startDate.getDateTime())) {
throw new IllegalArgumentException("The start date/time must come before the end date/time.");
}
}
// Note: History requests are not replicated throughout the cluster and are instead handled by the nodes independently
// create a history query
final HistoryQueryDTO query = new HistoryQueryDTO();
query.setSortColumn(sortColumn);
query.setSortOrder(sortOrder);
query.setOffset(offset.getInteger());
query.setCount(count.getInteger());
// optionally set the start date
if (startDate != null) {
query.setStartDate(startDate.getDateTime());
}
// optionally set the end date
if (endDate != null) {
query.setEndDate(endDate.getDateTime());
}
// optionally set the user id
if (userIdentity != null) {
query.setUserIdentity(userIdentity);
}
// optionally set the processor id
if (sourceId != null) {
query.setSourceId(sourceId);
}
// perform the query
final HistoryDTO history = serviceFacade.getActions(query);
// create the response entity
final HistoryEntity entity = new HistoryEntity();
entity.setHistory(history);
// generate the response
return generateOkResponse(entity).build();
}
use of org.apache.nifi.web.api.dto.action.HistoryDTO in project nifi by apache.
the class StandardNiFiServiceFacadeTest method testGetActionsForUser2.
@Test
public void testGetActionsForUser2() throws Exception {
// set the user
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_2).build()));
SecurityContextHolder.getContext().setAuthentication(authentication);
final HistoryDTO dto = serviceFacade.getActions(new HistoryQueryDTO());
// verify user 2 only has access to actions for processor 2
dto.getActions().forEach(action -> {
if (PROCESSOR_ID_1.equals(action.getSourceId())) {
assertFalse(action.getCanRead());
assertNull(action.getAction());
} else if (PROCESSOR_ID_2.equals(action.getSourceId())) {
assertTrue(action.getCanRead());
}
});
}
use of org.apache.nifi.web.api.dto.action.HistoryDTO in project nifi by apache.
the class StandardNiFiServiceFacadeTest method testGetActionsForUser1.
@Test
public void testGetActionsForUser1() throws Exception {
// set the user
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_1).build()));
SecurityContextHolder.getContext().setAuthentication(authentication);
final HistoryDTO dto = serviceFacade.getActions(new HistoryQueryDTO());
// verify user 1 only has access to actions for processor 1
dto.getActions().forEach(action -> {
if (PROCESSOR_ID_1.equals(action.getSourceId())) {
assertTrue(action.getCanRead());
} else if (PROCESSOR_ID_2.equals(action.getSourceId())) {
assertFalse(action.getCanRead());
assertNull(action.getAction());
}
});
}
Aggregations