sentilo-catalog-web/src/main/java/org/sentilo/web/catalog/domain/Alert.java
/*
* Sentilo
*
* Original version 1.4 Copyright (C) 2013 Institut Municipal d’Informàtica, Ajuntament de
* Barcelona. Modified by Opentrends adding support for multitenant deployments and SaaS.
* Modifications on version 1.5 Copyright (C) 2015 Opentrends Solucions i Sistemes, S.L.
*
*
* This program is licensed and may be used, modified and redistributed under the terms of the
* European Public License (EUPL), either version 1.1 or (at your option) any later version as soon
* as they are approved by the European Commission.
*
* Alternatively, you may redistribute and/or modify this program under the terms of the GNU Lesser
* General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied.
*
* See the licenses for the specific language governing permissions, limitations and more details.
*
* You should have received a copy of the EUPL1.1 and the LGPLv3 licenses along with this program;
* if not, you may find them at:
*
* https://joinup.ec.europa.eu/software/page/eupl/licence-eupl http://www.gnu.org/licenses/ and
* https://www.gnu.org/licenses/lgpl.txt
*/
package org.sentilo.web.catalog.domain;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import org.sentilo.common.enums.AlertTriggerType;
import org.sentilo.common.enums.AlertType;
import org.sentilo.web.catalog.utils.Constants;
import org.sentilo.web.catalog.utils.enums.EntityType;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;
@Document
public class Alert implements SectorResourceGranted, EntityResource, SyncResource, AlphabeticalSortable {
private static final long serialVersionUID = 1L;
@Id
@NotBlank
@Pattern(regexp = Constants.VALIDATION_ENTITY_NAME_REGEXP)
private String id;
private String name;
private String description;
@DateTimeFormat(pattern = Constants.DATETIME_FORMAT)
private Date createdAt;
private String createdBy;
@DateTimeFormat(pattern = Constants.DATETIME_FORMAT)
private Date updatedAt;
private String updatedBy;
private AlertType type;
private AlertTriggerType trigger;
private String expression;
private boolean active;
/**
* Identificador del proveedor al cual esta asociada la alerta en el caso de que sea
* interna/externa.
*/
private String providerId;
/**
* Identificador del componente al cual esta asociada la alerta en el caso de que sea interna.
*/
private String componentId;
/**
* Identificador del sensor al cual esta asociada la alerta en el caso de que sea interna.
*/
private String sensorId;
/**
* Identificador de la aplicación que registra la alerta en el caso de que esta sea externa.
*/
private String applicationId;
/**
* Identificador de la organización a la que pertenece la alerta
*/
private String tenantId;
/**
* Listado de organizaciones con permisos sobre la alerta
*/
private Set<String> tenantsAuth;
/**
* Listado de organizaciones con permisos de listado sobre la alerta
*/
private Set<String> tenantsListVisible;
private List<SectorGrant> sectors;
public Alert() {
tenantsAuth = new HashSet<String>();
tenantsListVisible = new HashSet<String>();
sectors = new ArrayList<SectorGrant>();
}
public Alert(final String id) {
this();
this.id = id;
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof Alert) || id == null) {
return false;
}
final Alert other = (Alert) obj;
return id.equals(other.id);
}
@Override
public int hashCode() {
// Hashcode return must be consistent with the equals method
final int prime = 17;
int result = 1;
result = prime * result + (id == null ? 0 : id.hashCode());
return result;
}
@Override
public String getEntityOwner() {
return StringUtils.hasText(providerId) ? providerId : applicationId;
}
@Override
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
@Override
public Date getCreatedAt() {
return createdAt;
}
@Override
public void setCreatedAt(final Date createdAt) {
this.createdAt = createdAt;
}
public AlertType getType() {
return type;
}
public void setType(final AlertType type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public String getSensorId() {
return sensorId;
}
public void setSensorId(final String sensorId) {
this.sensorId = sensorId;
}
public String getExpression() {
return expression;
}
public void setExpression(final String expression) {
this.expression = expression;
}
public AlertTriggerType getTrigger() {
return trigger;
}
public void setTrigger(final AlertTriggerType trigger) {
this.trigger = trigger;
}
@Override
public void setUpdatedAt(final Date updatedAt) {
this.updatedAt = updatedAt;
}
@Override
public Date getUpdatedAt() {
return updatedAt;
}
public String getProviderId() {
return providerId;
}
public void setProviderId(final String providerId) {
this.providerId = providerId;
}
public String getComponentId() {
return componentId;
}
public void setComponentId(final String componentId) {
this.componentId = componentId;
}
public void setApplicationId(final String applicationId) {
this.applicationId = applicationId;
}
public String getApplicationId() {
return applicationId;
}
@Override
public String getTenantId() {
return tenantId;
}
@Override
public void setTenantId(final String tenantId) {
this.tenantId = tenantId;
}
@Override
public Set<String> getTenantsAuth() {
return tenantsAuth;
}
@Override
public void setTenantsAuth(final Set<String> tenantsAuth) {
this.tenantsAuth = tenantsAuth;
}
@Override
public String getCreatedBy() {
return createdBy;
}
@Override
public void setCreatedBy(final String createdBy) {
this.createdBy = createdBy;
}
@Override
public String getUpdatedBy() {
return updatedBy;
}
@Override
public void setUpdatedBy(final String updatedBy) {
this.updatedBy = updatedBy;
}
public boolean isActive() {
return active;
}
public void setActive(final boolean active) {
this.active = active;
}
@Override
public Set<String> getTenantsListVisible() {
return tenantsListVisible;
}
@Override
public void setTenantsListVisible(final Set<String> tenantsListVisible) {
this.tenantsListVisible = tenantsListVisible;
}
@Override
public String getSortableValue() {
return name;
}
@Override
public List<SectorGrant> getSectors() {
return sectors;
}
@Override
public void setSectors(final List<SectorGrant> sectors) {
this.sectors = sectors;
}
@Override
public EntityType getEntityType() {
return StringUtils.hasText(providerId) ? EntityType.PROVIDER : EntityType.APPLICATION;
}
}