@Override public int hashCode() { // Hashcode return must be consistent with the equals method final int prime = 17; int result = 1; result = prime * result + fromTsTime.hashCode() + (SentiloUtils.arrayIsEmpty(coordinates) ? 0 : coordinates.hashCode()); return result; }
public static String buildPath(final String... pathTokens) { final StringBuilder sb = new StringBuilder(); if (!SentiloUtils.arrayIsEmpty(pathTokens)) { for (final String pathToken : pathTokens) { sb.append(SentiloConstants.SLASH).append(pathToken); } } return sb.toString(); } }
/** * Add the specified values to the beginning of the list. * * @param baseList * @param values */ public static List<String> addValuesToBeginningList(final List<String> baseList, final String... values) { final List<String> result = new ArrayList<String>(); if (!arrayIsEmpty(values)) { final List<String> valuesList = Arrays.asList(values); result.addAll(valuesList); } result.addAll(baseList); return result; }
private List<TenantPermission> toPermissionList(final String[] selectedIds) { final List<TenantPermission> permissions = new ArrayList<TenantPermission>(); if (!SentiloUtils.arrayIsEmpty(selectedIds)) { for (final String id : selectedIds) { final TenantPermission permission = new TenantPermission(id); permissions.add(permission); } } return permissions; }
private boolean arraysIdsAreEmpty(final TenantPermissionsDTO permission) { return SentiloUtils.arrayIsEmpty(permission.getSelectedProvidersIds()) || SentiloUtils.arrayIsEmpty(permission.getSelectedEntitiesIds()); }
private List<Permission> toPermissionList(final String[] selectedIds) { final List<Permission> permissions = new ArrayList<Permission>(); if (!SentiloUtils.arrayIsEmpty(selectedIds)) { for (final String id : selectedIds) { final Permission permission = new Permission(); permission.setId(id); permissions.add(permission); } } return permissions; }
public String toString() { final StringBuilder sb = new StringBuilder(); boolean first = true; if (!SentiloUtils.arrayIsEmpty(coordinates)) { for (final LngLat coordinate : coordinates) { if (!first) { sb.append(Constants.LOCATION_TOKEN_SPLITTER); } sb.append(coordinate.getLatitude()); sb.append(Constants.LOCATION_TOKEN_DIVIDER); sb.append(coordinate.getLongitude()); first = false; } } return sb.toString(); }
protected SearchFilter buildSearchFilter(final String[] componentTypes, final String[] bounds) { // If user is not logged in then only public components must be returned // It will be calculated in this build filter method final SearchFilter filter = getSearchFilterBuilder().buildMapSearchFilter(); if (!SentiloUtils.arrayIsEmpty(componentTypes)) { filter.addAndParam("componentType", componentTypes); } if (!SentiloUtils.arrayIsEmpty(bounds)) { filter.setMapBounds(bounds); } return filter; }
private String extractHeader(final HttpHeader header) { LOGGER.debug("extractHeader: {}", header.toString()); final Header[] requestHeaders = httpRequest.getHeaders(header.toString()); return SentiloUtils.arrayIsEmpty(requestHeaders) ? null : requestHeaders[0].getValue(); }
@RequestMapping(value = "/{id}/addComponents", method = RequestMethod.POST) public String assignComponents(@PathVariable final String id, @Valid final ComponentComponentsDTO componentComponents, final BindingResult result, final Model model) { if (!SentiloUtils.arrayIsEmpty(componentComponents.getSelectedIds())) { getComponentService().updateMulti(Arrays.asList(componentComponents.getSelectedIds()), PARENT_ID_ATTRIBUTE, id); } ModelUtils.addConfirmationMessageTo(model, "component.assigned"); ModelUtils.addOpenedTabTo(model, Constants.TAB_2); addResourceToModel(id, model); return Constants.VIEW_COMPONENT_DETAIL; }
@RequestMapping(value = "/{id}/removeComponents", method = RequestMethod.POST) public String removeComponents(@PathVariable final String id, @Valid final ComponentsDTO components, final BindingResult result, final Model model) { if (!SentiloUtils.arrayIsEmpty(components.getSelectedIds())) { getComponentService().updateMulti(Arrays.asList(components.getSelectedIds()), PARENT_ID_ATTRIBUTE, null); } ModelUtils.addConfirmationMessageTo(model, "component.unassigned"); ModelUtils.addOpenedTabTo(model, Constants.TAB_2); addResourceToModel(id, model); return Constants.VIEW_COMPONENT_DETAIL; }
@RequestMapping(value = "/{id}/removeSensors", method = RequestMethod.POST) public String removeSensors(@PathVariable final String id, @Valid final ComponentSensorsDTO sensors, final BindingResult result, final Model model) { if (!SentiloUtils.arrayIsEmpty(sensors.getSelectedIds())) { getSensorService().updateMulti(Arrays.asList(sensors.getSelectedIds()), COMPONENT_ID_ATTRIBUTE, null); } ModelUtils.addConfirmationMessageTo(model, "sensor.unassigned"); ModelUtils.addOpenedTabTo(model, Constants.TAB_3); addResourceToModel(id, model); return Constants.VIEW_COMPONENT_DETAIL; }
@RequestMapping(value = "/entity/{entityId}/delete", method = RequestMethod.PUT) @ResponseBody public CatalogAlertResponseMessage deleteAlerts(@PathVariable final String entityId, @RequestBody(required = false) final CatalogAlertInputMessage message) { // Solo se pueden borrar alarmas externas de las cuales se es el propietario. // Las alarmas internas solo se pueden borrar via la web. LOGGER.debug("Catalog alert API: deleting alerts. Operation invoked by entity {} ", entityId); try { if (message == null || SentiloUtils.arrayIsEmpty(message.getAlertsIds())) { alertService.deleteOwnAlerts(entityId); LOGGER.debug("Catalog alert API: deleted all alerts from entity {}", entityId); } else if (!SentiloUtils.arrayIsEmpty(message.getAlertsIds())) { alertService.deleteOwnAlerts(message.getAlertsIds(), entityId); LOGGER.debug("Catalog alert API: deleted {} alerts", message.getAlertsIds().length); } } catch (final Exception ex) { final String internalErrorCode = SentiloUtils.buildNewInternalErrorCode(SentiloConstants.CATALOG_API_ERROR); LOGGER.error("{} - Error deleting alerts. ", internalErrorCode, ex); final String errorMessage = String.format(SentiloConstants.INTERNAL_ERROR_MESSAGE_TEMPLATE, internalErrorCode); return new CatalogAlertResponseMessage(errorMessage); } return new CatalogAlertResponseMessage(); } }
public AbstractHandler lookup(final SentiloRequest request) { final String path = request.getPath(); // If path is /token1/token2/ ... /tokenN , there are two possibilities to handlerPath value // /token1/token2 // or // /token1 AbstractHandler handler = null; final String[] tokens = RequestUtils.splitPath(path); if (!SentiloUtils.arrayIsEmpty(tokens)) { final Queue<String> handlerPathCandidates = new ArrayDeque<String>(); if (tokens.length > 2) { handlerPathCandidates.add(RequestUtils.buildPath(tokens[1], tokens[2])); } handlerPathCandidates.add(RequestUtils.buildPath(tokens[1])); while (!CollectionUtils.isEmpty(handlerPathCandidates)) { final String handlerPath = handlerPathCandidates.poll(); handler = handlers.get(handlerPath); if (handler != null) { final String resourcePath = RequestUtils.extractResource(path, handlerPath); request.setPathParts(handlerPath, resourcePath); break; } } } return handler; }
public SearchFilterResult<Component> geoSpatialSearch(final SearchFilter filter) { if (SentiloUtils.arrayIsEmpty(filter.getBounds())) { return super.search(filter); } // bounds = [lat_lo_left,lng_lo_left,lat_hi_west,lng_hi_west] final String[] mapBounds = filter.getBounds(); final double[] lowerLeft = {Double.parseDouble(mapBounds[1]), Double.parseDouble(mapBounds[0])}; final double[] upperRight = {Double.parseDouble(mapBounds[3]), Double.parseDouble(mapBounds[2])}; final Box mapBox = new Box(lowerLeft, upperRight); final Criteria geoSpatialCriteria = Criteria.where("location.centroid").within(mapBox); final Query query = buildQuery(filter, false, geoSpatialCriteria); LOGGER.debug("GeoSpatial Search - query: {}", query); final List<Component> content = getMongoOps().find(query, Component.class); return new SearchFilterResult<Component>(content, filter, content.size()); }
@Override public void validate(final Object target, final Errors errors) { final PermissionsDTO permissions = (PermissionsDTO) target; if (SentiloUtils.arrayIsEmpty(permissions.getSelectedApplicationsIds()) && SentiloUtils.arrayIsEmpty(permissions.getSelectedProvidersIds())) { errors.reject(ERROR_CODE_EMPTY_SELECTED_IDS); return; } if (TenantContextHolder.isEnabled()) { final Permission.Type type = permissions.getPermissionType(); switch (type) { case ADMIN: validateAdminPermissions(permissions, errors); break; case WRITE: validateWritePermissions(permissions, errors); break; default: break; } } }
@Override public void validate(final Object target, final Errors errors) { if (target instanceof Component) { final Component component = (Component) target; if (component.isStaticComponent() && (component.getLocation() == null || SentiloUtils.arrayIsEmpty(component.getLocation().getCoordinates()))) { errors.rejectValue("location", Constants.NOT_BLANK_ERROR); } return; } }
public void checkAccess(final AccessControlContext acc) { if (userDetailsService.getCatalogUserDetails() == null) { LOGGER.error("Anonymous users are not allowed to {} resources of type {}", acc.getAction().name(), acc.getResourceClass().getName()); throw new NotAllowedActionException(); } final CatalogUserDetails userDetails = userDetailsService.getCatalogUserDetails(); final String userRole = userDetails.isSuperAdminUser() ? "SA" : userDetails.isAdminUser() ? "A" : "U"; final ActionGrant[] grants = aclRepository.getGrants(acc.getResourceClass(), userRole); if (SentiloUtils.arrayIsEmpty(grants) || !checkGrants(grants, userDetails, acc)) { LOGGER.error("User {} is not allowed to {} resources of type {} ", userDetails.getUsername(), acc.getAction().name(), acc.getResourceClass().getName()); throw new NotAllowedActionException(); } }
private void validateLocationContent(final ApiValidationResults results, final Component component) { if (component.getLocation() != null && !SentiloUtils.arrayIsEmpty(component.getLocation().getCoordinates())) { final LngLat[] coordinates = component.getLocation().getCoordinates(); boolean valid = true; for (int i = 0; i < coordinates.length && valid; i++) { final DataBinder binder = new DataBinder(coordinates[i]); binder.setValidator(getValidator()); binder.validate(); valid = binder.getBindingResult().hasErrors() ? false : true; } if (!valid) { final String errorMessage = buildErrorMessage(COMPONENT, component.getName(), "location", Arrays.toString(coordinates)); results.addErrorMessage(errorMessage); } } }
/** * Build the centroid of a set of coordinates * * @param location * @return */ public static void build(final Location location) { Double[] centroid = null; if (!SentiloUtils.arrayIsEmpty(location.getCoordinates())) { // The centroid of a polyline (open or closed) is obtained by finding the midpoints of each // line segment and then forming their weighted average using the segment lengths as weights. // And to calculate the centroid we can treat latitude and longitude as Cartesian coordinates: // location points are so close to each other, in a global vision, that we can consider the // Earth locally flat. if (location.getNumberOfCoordinates() == 1) { centroid = location.getCoordinates()[0].toArray(); } else { centroid = calculatePolylineCentroid(location.getCoordinates()); } location.setCentroid(centroid); } }