@Override public void delete(final AdminInputMessage message) { // This method must remove everything stored in Redis related to sensors, providers or alerts. // The data, such as observations, orders and alarms, does not need be removed because them have // a ttl associated with and Redis automatically deleted them. // Furthermore, these data will be orphaned so them cannot be retrieved with the API REST. if (!CollectionUtils.isEmpty(message.getProviders())) { deleteProviders(message.getProviders()); } else if (!CollectionUtils.isEmpty(message.getSensors())) { deleteSensors(message.getSensors()); } else if (!CollectionUtils.isEmpty(message.getAlerts())) { deleteAlerts(message.getAlerts()); } }
public AdminInputMessage(final AdminType type) { this(); setType(type); }
public AdminInputMessage parseGetRequest(final SentiloRequest request) throws PlatformException { final AdminType type = getAdminType(request); final AdminInputMessage inputMessage = new AdminInputMessage(type); inputMessage.setEntity(request.getResourcePart(1)); return inputMessage; }
@Override public void save(final AdminInputMessage message) { // This method gets either a sensors or alerts list and should created/update each one in Redis if (!CollectionUtils.isEmpty(message.getSensors())) { saveSensors(message); } if (!CollectionUtils.isEmpty(message.getAlerts())) { saveAlerts(message); } }
protected void processOnPostOrPutRequest(final SentiloRequest request, final SentiloResponse response) { validateResourceNumberParts(request, 1, 1); validateApiAdminInvoke(request.getEntitySource()); final AdminInputMessage inputMessage = parser.parsePostPutRequest(request); validator.validateRequestMessageOnPut(inputMessage); LOGGER.debug("Type message: {}", inputMessage.getType()); LOGGER.debug("Sensors: {}", !CollectionUtils.isEmpty(inputMessage.getSensors()) ? inputMessage.getSensors().size() : 0); LOGGER.debug("Providers: {}", !CollectionUtils.isEmpty(inputMessage.getProviders()) ? inputMessage.getProviders().size() : 0); LOGGER.debug("Alerts: {}", !CollectionUtils.isEmpty(inputMessage.getAlerts()) ? inputMessage.getAlerts().size() : 0); switch (inputMessage.getType()) { case delete: adminService.delete(inputMessage); break; case save: adminService.save(inputMessage); break; default: throw new MessageValidationException(String.format("Request %s not supported", request.getUri())); } }
@Override public void validateRequestMessageOnGet(final AdminInputMessage requestMessage) throws MessageValidationException { Assert.notNull(requestMessage); if (AdminType.subscriptions.equals(requestMessage.getType()) && !StringUtils.hasText(requestMessage.getEntity())) { throw new MessageValidationException("To get subscriptions from an entity is mandatory to inform the entity"); } super.validateRequestMessageOnGet(requestMessage); } }
private void saveSensors(final AdminInputMessage message) { for (final CatalogSensor sensor : message.getSensors()) { LOGGER.debug("Saving sensor [{}] belonging to provider [{}]", sensor.getSensor(), sensor.getProvider()); registerProviderAndSensorIfNeedBe(sensor); } }
private void saveAlerts(final AdminInputMessage message) { // For each alert, if it already exist then it should be updated. Otherwise, it should be // created for (final CatalogAlert alert : message.getAlerts()) { LOGGER.debug("Saving alert [{}] belonging to entity [{}]", alert.getId(), alert.getEntity()); resourceService.registerAlertIfNeedBe(alert, true); } }
validator.validateRequestMessageOnGet(inputMessage); switch (inputMessage.getType()) { case stats: final Statistics stats = adminService.getStatistics(); break; case subscriptions: final List<Subscription> subscriptions = adminService.getSubscriptions(inputMessage.getEntity()); parser.writeSubscriptionsResponse(response, subscriptions); break;
public AdminInputMessage parsePostPutRequest(final SentiloRequest request) throws PlatformException { final AdminType type = getAdminType(request); final AdminInputMessage inputMessage = (AdminInputMessage) readInternal(AdminInputMessage.class, request); inputMessage.setType(type); return inputMessage; }