diff --git a/.gitignore b/.gitignore index 6720dd5acb79fd10b18ae6e99c2c4c8f6047e982..2d696702eb77a863ad3c0c3f4ed46869cb20ff92 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ hs_err_pid* activemq-data/ /bin/ + +src/main/java/c2mon-client.properties diff --git a/.gradle/7.4/checksums/checksums.lock b/.gradle/7.4/checksums/checksums.lock index 348bf145da95bead0a93a051e82aecc479000233..8a196d8059c734c62715f5b9bcad666d77b64be3 100644 Binary files a/.gradle/7.4/checksums/checksums.lock and b/.gradle/7.4/checksums/checksums.lock differ diff --git a/.gradle/7.4/checksums/md5-checksums.bin b/.gradle/7.4/checksums/md5-checksums.bin index ec9c37a1f756da9db8579842b26ad52335939b3e..f6f6ba912aade23222f40a10de5102d882deeb9a 100644 Binary files a/.gradle/7.4/checksums/md5-checksums.bin and b/.gradle/7.4/checksums/md5-checksums.bin differ diff --git a/.gradle/7.4/checksums/sha1-checksums.bin b/.gradle/7.4/checksums/sha1-checksums.bin index 008d46111a28c526b90398c18542c37fba13ca98..6a5c4d89084c61131427e4d42beb2cccb1ed9753 100644 Binary files a/.gradle/7.4/checksums/sha1-checksums.bin and b/.gradle/7.4/checksums/sha1-checksums.bin differ diff --git a/.gradle/7.4/executionHistory/executionHistory.bin b/.gradle/7.4/executionHistory/executionHistory.bin index 0c644c439851da10becaa7c1d5821ced71dc2e4e..0cd580bd61e1adfb5443882039c98c6ae780ecf8 100644 Binary files a/.gradle/7.4/executionHistory/executionHistory.bin and b/.gradle/7.4/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.4/executionHistory/executionHistory.lock b/.gradle/7.4/executionHistory/executionHistory.lock index c5b527bd1ce1bceecf8e9a4c2f6239025e26bf0b..1187cdddb3f6a1d9bffbb124fb4aeeffab8b7928 100644 Binary files a/.gradle/7.4/executionHistory/executionHistory.lock and b/.gradle/7.4/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.4/fileHashes/fileHashes.bin b/.gradle/7.4/fileHashes/fileHashes.bin index a385c5906f7206de696baf5837fa5d6a649d4a24..fa861da7816e7d5421f72aacfbdfcc964e879b65 100644 Binary files a/.gradle/7.4/fileHashes/fileHashes.bin and b/.gradle/7.4/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.4/fileHashes/fileHashes.lock b/.gradle/7.4/fileHashes/fileHashes.lock index 4c2a188d9635901c90ac0175125664560d5e125c..6478f3aea11206434689686be5e14dd75bedfb44 100644 Binary files a/.gradle/7.4/fileHashes/fileHashes.lock and b/.gradle/7.4/fileHashes/fileHashes.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 5c3aea970bec7143960884a05a36fa282e4e0112..cf7cc36183b12e82b95221dd5563e5c8ec6d09fe 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/product.xml b/product.xml index 24cc9f37b9bbcba4523a1adcbe0795866c0d7231..a54526113ff03c02056021d9e01378e6b353791f 100644 --- a/product.xml +++ b/product.xml @@ -10,6 +10,8 @@ <dep groupId="org.mybatis" product="mybatis-spring" version="2.0.6"/> <!-- 3rd party dependencies --> + <dep groupId="com.fasterxml.jackson.dataformat" product="jackson-dataformat-xml" version="2.11.1"/> + <dep groupId="com.fasterxml.jackson.datatype" product="jackson-datatype-jsr310"/> <dep groupId="org.hsqldb" product="hsqldb" version="2.3.4"/> <dep groupId="org.springframework" product="spring-context" version="5.1.2.RELEASE"/> <dep groupId="org.springframework.boot" product="spring-boot" version="2.1.1.RELEASE"/> diff --git a/src/main/java/cern/c2mon/client/ext/history/alarm/AlarmRecord.java b/src/main/java/cern/c2mon/client/ext/history/alarm/AlarmRecord.java index a4e8a4d07694e084f469ee7dc54ecda42c5767d2..a64d6000f97f89bd06f44243deb8bea97707b553 100644 --- a/src/main/java/cern/c2mon/client/ext/history/alarm/AlarmRecord.java +++ b/src/main/java/cern/c2mon/client/ext/history/alarm/AlarmRecord.java @@ -17,14 +17,20 @@ package cern.c2mon.client.ext.history.alarm; +import cern.c2mon.client.ext.history.data.utilities.MapConverter; import lombok.Data; import org.hibernate.annotations.Type; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; + +import java.time.Instant; import java.time.LocalDateTime; +import java.util.Map; + @Entity @Data @@ -38,6 +44,9 @@ public class AlarmRecord { @Column(name = "alarm_tagid") private Long tagId; + @Column(name = "alarmpriority") + private Integer alarmPriority; + @Column(name = "alarmffamily") private String faultFamily; @@ -57,9 +66,25 @@ public class AlarmRecord { @Column(name ="alarmsourcetime") private LocalDateTime sourceTimestamp; +// @Column(name ="alarmtime", insertable = false, updatable = false) +// private Instant instantTimestamp; + +// @Column(name ="alarmsourcetime", insertable = false, updatable = false) +// private Instant instantSourceTimestamp; + @Column(name = "alarminfo") private String info; @Column(name = "alarmmetadata") private String metadata; + +// @Column(name = "alarmmetadata", insertable = false, updatable = false) +// @Convert(converter = MapConverter.class) +// private Map<String, Object> metadataMap; + + @Column(name = "alarmoscillation") + private Boolean alarmOscillation; + + @Column(name = "alarmcondition") + private String alarmCondition; } diff --git a/src/main/java/cern/c2mon/client/ext/history/alarm/repo/AlarmHistoryService.java b/src/main/java/cern/c2mon/client/ext/history/alarm/repo/AlarmHistoryService.java index 8c0387474c48dcf73d481808695d0163edd5403f..9a48d2806a98bfd554304c420848c6fa9de75c29 100644 --- a/src/main/java/cern/c2mon/client/ext/history/alarm/repo/AlarmHistoryService.java +++ b/src/main/java/cern/c2mon/client/ext/history/alarm/repo/AlarmHistoryService.java @@ -19,13 +19,14 @@ package cern.c2mon.client.ext.history.alarm.repo; import java.time.LocalDateTime; import java.util.List; -import cern.c2mon.client.ext.history.alarm.AlarmLog; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import cern.c2mon.client.ext.history.alarm.AlarmLog; + /** * This service allows querying {@link AlarmLog} history from the c2mon history database. * diff --git a/src/main/java/cern/c2mon/client/ext/history/alarm/repo/AlarmRepoService.java b/src/main/java/cern/c2mon/client/ext/history/alarm/repo/AlarmRepoService.java index b74081857adf0e59e61bdb0060e2b19ebd99c32a..12078f7d08b1393b0609a7451d6f07397221b94f 100644 --- a/src/main/java/cern/c2mon/client/ext/history/alarm/repo/AlarmRepoService.java +++ b/src/main/java/cern/c2mon/client/ext/history/alarm/repo/AlarmRepoService.java @@ -1,10 +1,18 @@ package cern.c2mon.client.ext.history.alarm.repo; import cern.c2mon.client.ext.history.alarm.AlarmRecord; +import cern.c2mon.client.ext.history.es_publisher.entity.ShortTermLog; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Service; +import java.time.Instant; +import java.time.ZonedDateTime; + import java.util.List; import java.util.Optional; @@ -70,6 +78,10 @@ public interface AlarmRepoService extends JpaRepository<AlarmRecord, Long> { @Param("faultMember") String faultMember, @Param("faultCode") Integer faultCode); + List<AlarmRecord> findByInstantTimestampBetween( + Instant from, + Instant to); + List<AlarmRecord> findByTagId(Long tagId); diff --git a/src/main/java/cern/c2mon/client/ext/history/config/HistoryConfig.java b/src/main/java/cern/c2mon/client/ext/history/config/HistoryConfig.java index 20e7447254acdeedc27d31cf5e03eb67ca5c6083..fc711a4109db7851f73be4de2fba3304ee6dd416 100644 --- a/src/main/java/cern/c2mon/client/ext/history/config/HistoryConfig.java +++ b/src/main/java/cern/c2mon/client/ext/history/config/HistoryConfig.java @@ -24,6 +24,6 @@ import org.springframework.context.annotation.PropertySource; * @author Justin Lewis Salmon */ @Configuration -@PropertySource("classpath:history.properties") +@PropertySource("file:etc/history.properties") @ImportResource("classpath:config/c2mon-client-ext-history.xml") public class HistoryConfig {} diff --git a/src/main/java/cern/c2mon/client/ext/history/data/DataTagLog.java b/src/main/java/cern/c2mon/client/ext/history/data/DataTagLog.java deleted file mode 100644 index e243a490fe9ff911d19d9494877348140a79c7a3..0000000000000000000000000000000000000000 --- a/src/main/java/cern/c2mon/client/ext/history/data/DataTagLog.java +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2010-2016 CERN. All rights not expressly granted are reserved. - * - * This file is part of the CERN Control and Monitoring Platform 'C2MON'. - * C2MON is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the license. - * - * C2MON is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with C2MON. If not, see <http://www.gnu.org/licenses/>. - *****************************************************************************/ -package cern.c2mon.client.ext.history.data; - - -import cern.c2mon.client.ext.history.alarm.config.JpaConfiguration; -import lombok.Data; -import org.hibernate.annotations.Type; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.time.LocalDateTime; - -/** - * Entity bean for historical alarm values. - * - * @author Justin Lewis Salmon - */ -@Entity -@Data -@Table(name = "alarmlog") -public class DataTagLog { - - /** - * The local alarm timestamp. In the database it is stored as UTC timestamp. - * @see JpaConfiguration - */ - @Id - @Column(name = "servertime") - private LocalDateTime timestamp; - - @Column(name = "alarmid") - private Long id; - - @Column(name = "tagid") - private Long tagId; - - @Column(name = "faultcode") - private int faultCode; - - @Column(name = "faultfamily") - private String faultFamily; - - @Column(name = "faultmember") - private String faultMember; - - @Column(name ="sourcetime") - private LocalDateTime sourceTime; - - @Type(type="yes_no") - private boolean active; - - private String info; -} diff --git a/src/main/java/cern/c2mon/client/ext/history/data/DataTagRecord.java b/src/main/java/cern/c2mon/client/ext/history/data/DataTagRecord.java index 4b0b86b5a513dee5f4ce6e4d011d3e4c3fe93c87..b1517990442ff78fc6a593b2d1493ab717022675 100644 --- a/src/main/java/cern/c2mon/client/ext/history/data/DataTagRecord.java +++ b/src/main/java/cern/c2mon/client/ext/history/data/DataTagRecord.java @@ -1,16 +1,56 @@ package cern.c2mon.client.ext.history.data; +import java.time.Instant; +import java.util.List; +import java.util.Map; + +import cern.c2mon.client.ext.history.alarm.AlarmRecord; +import cern.c2mon.client.ext.history.equipment.EquipmentRecord; +import cern.c2mon.client.ext.history.data.utilities.MapConverter; +import cern.c2mon.client.ext.history.process.Process; +import cern.c2mon.shared.client.configuration.api.equipment.Equipment; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Convert; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import java.time.Instant; +import java.util.List; +import java.util.Map; + +import cern.c2mon.client.ext.history.alarm.AlarmRecord; +import cern.c2mon.client.ext.history.equipment.EquipmentRecord; +import cern.c2mon.client.ext.history.data.utilities.MapConverter; +import cern.c2mon.client.ext.history.process.Process; +import cern.c2mon.shared.client.configuration.api.equipment.Equipment; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; +import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; import javax.persistence.Table; import org.hibernate.annotations.Type; @Entity @Data +@NoArgsConstructor @Table(name = "datatag") public class DataTagRecord { @@ -27,4 +67,59 @@ public class DataTagRecord { @Column(name = "tagcontroltag") @Type(type="yes_no") private boolean controlTag; + + @Column(name = "tagmode") + private Integer tagMode;//TAGMODE INTEGER NOT NULL, + + @Column(name = "tagdatatype") + private Class<?> tagDataType;//TAGDATATYPE VARCHAR(200) NOT NULL, + + @Column(name = "tagvalue") + private String tagValue; + + @Column(name = "tagvaluedesc") + private String tagValueDesc; + + @Column(name = "tagtimestamp") + private Instant tagTimeStamp;//TAGTIMESTAMP TIMESTAMP(6), + + @Column(name = "tagdaqtimestamp") + private Instant tagDaqTimestamp; + + @Column(name = "tagsrvtimestamp") + private Instant tagServerTimestamp; + + @Column(name = "tagmetadata") + @Convert(converter = MapConverter.class) + private Map<String, Object> tagMetaData;//TAGMETADATA VARCHAR(4000), + + @Column(name = "tagqualitycode") + private Integer tagQualityCode; + + @Column(name = "tagQualityDesc") + private String tagQualityDesc; + + @Column(name = "tagrule") + private String tagRule; + + @Column(name = "tagruleids") + private String tagRuleIds; + + @Column(name = "tagunit") + private String tagUnit;//TAGUNIT VARCHAR(50), + + @Column(name = "tagSimulated") + private Boolean tagSimulated; + + @Column(name = "taglogged") + private Boolean tagLogged;//TAGLOGGED INTEGER, + + @OneToMany(mappedBy = "tagId", fetch= FetchType.EAGER) + private List<AlarmRecord> alarmList; + + @OneToOne(fetch= FetchType.EAGER) + @JoinColumn(name = "tag_eqid", referencedColumnName = "eqid") + private EquipmentRecord equipment; + + } diff --git a/src/main/java/cern/c2mon/client/ext/history/data/repo/DataTagRepoService.java b/src/main/java/cern/c2mon/client/ext/history/data/repo/DataTagRepoService.java index 514f8ae301f88adda84ce373f48db96ca98274eb..82934852e93403b496c8f9d08ba870d45d4299a8 100644 --- a/src/main/java/cern/c2mon/client/ext/history/data/repo/DataTagRepoService.java +++ b/src/main/java/cern/c2mon/client/ext/history/data/repo/DataTagRepoService.java @@ -17,7 +17,16 @@ package cern.c2mon.client.ext.history.data.repo; import cern.c2mon.client.ext.history.data.DataTagRecord; +import cern.c2mon.client.ext.history.supervision.ServerSupervisionEvent; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.time.Instant; + import java.util.List; import java.util.Optional; @@ -29,4 +38,17 @@ public interface DataTagRepoService extends JpaRepository<DataTagRecord, Long>{ List<DataTagRecord> findFirst10ByNameContainingIgnoreCase(String dataTagName); + @Query("SELECT a FROM DataTagRecord a WHERE " + + "a.tagServerTimestamp BETWEEN :startTime AND :endTime " + + "ORDER BY a.tagServerTimestamp ASC") + List<DataTagRecord> findByTagServerTimestampBetweenByOrderByTagTimeStampDesc( + @Param("startTime") Instant startTime, + @Param("endTime") Instant endTime); + + Page<DataTagRecord> findAllByTagServerTimestampAfterOrderByTagTimeStampAsc( + @Param("startTime") Instant startTime, + Pageable pageable); + + Page<DataTagRecord> findAllByOrderByTagTimeStampDesc(Pageable pageable); + } diff --git a/src/main/java/cern/c2mon/client/ext/history/data/utilities/MapConverter.java b/src/main/java/cern/c2mon/client/ext/history/data/utilities/MapConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..633c71af3e734f925a461faa2230aa908e921ede --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/data/utilities/MapConverter.java @@ -0,0 +1,43 @@ +package cern.c2mon.client.ext.history.data.utilities; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Converter +public class MapConverter implements AttributeConverter<Map<String, Object>, String> { + + private final ObjectMapper mapper = new ObjectMapper(); + + @Override + public String convertToDatabaseColumn(Map<String, Object> data) { + String value = ""; + try { + value = mapper.writeValueAsString(data); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return value; + } + + @Override + public Map<String, Object> convertToEntityAttribute(String data) { + + Map<String, Object> mapValue = new HashMap<String, Object>(); + TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { + }; + try { + mapValue = mapper.readValue(data, typeRef); + } catch (IOException e) { + e.printStackTrace(); + } + return mapValue; + } +} diff --git a/src/main/java/cern/c2mon/client/ext/history/equipment/EquipmentRecord.java b/src/main/java/cern/c2mon/client/ext/history/equipment/EquipmentRecord.java index 9f1fcc5e5a5ee7e5e96c6e4cdab7adbb3a49497b..65303b41be432316e1e048ebd175b92b6a31c2e0 100644 --- a/src/main/java/cern/c2mon/client/ext/history/equipment/EquipmentRecord.java +++ b/src/main/java/cern/c2mon/client/ext/history/equipment/EquipmentRecord.java @@ -1,10 +1,19 @@ package cern.c2mon.client.ext.history.equipment; +import java.util.Set; + +import cern.c2mon.client.ext.history.process.Process; +import cern.c2mon.client.ext.history.supervision.ServerSupervisionEvent; import lombok.Data; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @@ -28,7 +37,15 @@ public class EquipmentRecord { @Column(name = "eqstate_tagid") private Integer stateTagId; - /*@Column(name = "eqaddress") + @OneToOne(cascade = CascadeType.ALL, fetch= FetchType.EAGER) + @JoinColumn(name = "eq_procid", referencedColumnName = "procid", insertable = false, updatable = false) + private Process processData; + + /* + @OneToMany(mappedBy = "id", cascade = CascadeType.ALL, fetch = FetchType.EAGER) + private Set<ServerSupervisionEvent> supervisionEvent; + + @Column(name = "eqaddress") private String address; @Column(name = "eqalive_tagid") diff --git a/src/main/java/cern/c2mon/client/ext/history/es_publisher/AlarmData.java b/src/main/java/cern/c2mon/client/ext/history/es_publisher/AlarmData.java new file mode 100644 index 0000000000000000000000000000000000000000..e08fc9581685d343cd438863c4b146b2baf73e8e --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/es_publisher/AlarmData.java @@ -0,0 +1,75 @@ +package cern.c2mon.client.ext.history.es_publisher; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import lombok.Data; + +@Entity +@Data +@Table(name = "alarm") +public class AlarmData { + /* + "mode": 0, + "unit": null, + "metadata": { + "responsible": "Jon Doe", + "building": 200 + }, + "c2mon": { + "process": "P_daqrest1", + "logged": true, + "dataType": "java.lang.Double", + "equipment": "E_daqrest1" + }, + "alarms": [], + "name": "rack/XYZ/temperature", + "description": "<no description provided>", + "id": 1000004, + "timestamp": 1662039161805 + */ + + @Id + @Column(name = "ALARMID") + private Long alarmId; // INTEGER NOT NULL PRIMARY KEY, + + @Column(name = "ALARM_TAGID") + private Integer alarmTagId; + + @Column(name = "ALARMPRIORITY") + private Integer alarmPriority; // INTEGER, + + @Column(name = "ALARMFFAMILY") + private String alarmFamily; //ALARMFFAMILY VARCHAR(64) NOT NULL, + + @Column(name = "ALARMFMEMBER") + private String alarmFMember; //ALARMFMEMBER VARCHAR(64) NOT NULL, + + @Column(name = "ALARMFCODE") + private Integer alarmFCode; //ALARMFCODE INTEGER NOT NULL, + + @Column(name = "ALARMSTATE") + private String alarmState;// VARCHAR(10), + + @Column(name = "ALARMTIME") + private LocalDateTime alarmTime;// TIMESTAMP(6), + + @Column(name = "ALARMSOURCETIME") + private LocalDateTime alarmSourceTime;// TIMESTAMP(6), + + @Column(name = "ALARMINFO") + private String alarmInfo; //ALARMINFO VARCHAR(100), + + @Column(name = "ALARMCONDITION") + private String alarmCondition;// VARCHAR(500), + + @Column(name = "ALARMMETADATA") + private String alarmMetadata; //ALARMMETADATA VARCHAR(4000), + + @Column(name = "ALARMOSCILLATION") + private Integer alarmOscillation;// INTEGER +} diff --git a/src/main/java/cern/c2mon/client/ext/history/es_publisher/DataTagData.java b/src/main/java/cern/c2mon/client/ext/history/es_publisher/DataTagData.java new file mode 100644 index 0000000000000000000000000000000000000000..d00a7a862e67cffbeef85db2b872cedd2bf52318 --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/es_publisher/DataTagData.java @@ -0,0 +1,77 @@ +package cern.c2mon.client.ext.history.es_publisher; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Convert; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import lombok.Data; + +@Entity +@Data +@Table(name = "datatag") +public class DataTagData { + /* + "mode": 0, + "unit": null, + "metadata": { + "responsible": "Jon Doe", + "building": 200 + }, + "c2mon": { + "process": "P_daqrest1", + "logged": true, + "dataType": "java.lang.Double", + "equipment": "E_daqrest1" + }, + "alarms": [], + "name": "rack/XYZ/temperature", + "description": "<no description provided>", + "id": 1000004, + "timestamp": 1662039161805 + */ + + @Id + @Column(name = "tagId") + private Long tagId; // INTEGER NOT NULL PRIMARY KEY, + + @Column(name = "tagmode") + private Integer tagMode;//TAGMODE INTEGER NOT NULL, + + @Column(name = "tagunit") + private String tagUnit;//TAGUNIT VARCHAR(50), + + @Column(name = "tagmetadata") + @Convert(converter = MapToStringConverter.class) + private Map<String, String> tagMetaData;//TAGMETADATA VARCHAR(4000), + + @Column(name = "tagdatatype") + private String tagDataType;//TAGDATATYPE VARCHAR(200) NOT NULL, + + @Column(name = "tag_eqid") + private Integer tagEqId;//TAG_EQID INTEGER, + + @Column(name = "taglogged") + private Integer tagLogged;//TAGLOGGED INTEGER, + + @Column(name = "tagname") + private String tagName;//TAGNAME VARCHAR(255) NOT NULL UNIQUE, + + @Column(name = "tagdesc") + private String tagDesc;//TAGDESC VARCHAR(100), + + @Column(name = "tagtimestamp") + private LocalDateTime tagTimeStamp;//TAGTIMESTAMP TIMESTAMP(6), + + @OneToMany(mappedBy = "alarmTagId", cascade = CascadeType.ALL, fetch= FetchType.EAGER) + //@JoinColumn(name = "ALARM_TAGID") + private List<AlarmData> alarmList; +} diff --git a/src/main/java/cern/c2mon/client/ext/history/es_publisher/MapToStringConverter.java b/src/main/java/cern/c2mon/client/ext/history/es_publisher/MapToStringConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..be389c803db40d5a21a22dfb3d1ce02bc6b3e9c0 --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/es_publisher/MapToStringConverter.java @@ -0,0 +1,45 @@ +package cern.c2mon.client.ext.history.es_publisher; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import lombok.extern.slf4j.Slf4j; + +@Converter +public class MapToStringConverter implements AttributeConverter<Map<String, String>, String> { + + ObjectMapper mapper = new ObjectMapper(); + + @Override + public String convertToDatabaseColumn(Map<String, String> data) { + String value = ""; + try { + value = mapper.writeValueAsString(data); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return value; + } + + @Override + public Map<String, String> convertToEntityAttribute(String data) { + + Map<String, String> mapValue = new HashMap<String, String>(); + TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() { + }; + try { + mapValue = mapper.readValue(data, typeRef); + } catch (IOException e) { + e.printStackTrace(); + } + return mapValue; + } +} diff --git a/src/main/java/cern/c2mon/client/ext/history/es_publisher/ShortTermLog.java b/src/main/java/cern/c2mon/client/ext/history/es_publisher/ShortTermLog.java new file mode 100644 index 0000000000000000000000000000000000000000..a526afa49744aff273d9ffea4a7543c0d8133975 --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/es_publisher/ShortTermLog.java @@ -0,0 +1,45 @@ +package cern.c2mon.client.ext.history.es_publisher; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.springframework.context.annotation.Profile; + +import lombok.Data; + +@Entity +@Data +@Table(name = "shorttermlog") +public class ShortTermLog { + @Id + @Column(name = "tagservertime") + private LocalDateTime tagServerTime; + + @Column(name = "tagid") + private Long id; + + @Column(name = "tagdatatype") + private Class<?> tagDatatype; + + @Column(name ="tagtime") + private LocalDateTime tagTime; + + @Column(name ="tagdaqtime") + private LocalDateTime tagDaqTime; + + @Column(name = "tagstatusdesc") + private String tagStatusDesc; + + @Column(name = "tagname") + private String tagName; + + @Column(name = "tagvaluedesc") + private String tagValueDesc; + + @Column(name = "tagvalue") + private String tagValue; +} diff --git a/src/main/java/cern/c2mon/client/ext/history/es_publisher/entity/ShortTermLog.java b/src/main/java/cern/c2mon/client/ext/history/es_publisher/entity/ShortTermLog.java new file mode 100644 index 0000000000000000000000000000000000000000..672af3ef507766df329a2d3fb96d840bc636d41a --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/es_publisher/entity/ShortTermLog.java @@ -0,0 +1,43 @@ +package cern.c2mon.client.ext.history.es_publisher.entity; + +import java.time.Instant; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import lombok.Data; + +@Entity +@Data +@Table(name = "shorttermlog") +public class ShortTermLog { + @Id + @Column(name = "tagservertime") + private Instant tagServerTime; + + @Column(name = "tagid") + private Long id; + + @Column(name = "tagdatatype") + private Class<?> tagDatatype; + + @Column(name ="tagtime") + private Instant tagTime; + + @Column(name ="tagdaqtime") + private Instant tagDaqTime; + + @Column(name = "tagstatusdesc") + private String tagStatusDesc; + + @Column(name = "tagname") + private String tagName; + + @Column(name = "tagvaluedesc") + private String tagValueDesc; + + @Column(name = "tagvalue") + private String tagValue; +} diff --git a/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/ShortTermLogHistoryService.java b/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/ShortTermLogHistoryService.java new file mode 100644 index 0000000000000000000000000000000000000000..04e187be9ace9fd2ee2c269f511c2ca4454db6e8 --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/ShortTermLogHistoryService.java @@ -0,0 +1,32 @@ +package cern.c2mon.client.ext.history.es_publisher.repo; + +import java.time.LocalDateTime; +import java.util.List; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import cern.c2mon.client.ext.history.es_publisher.ShortTermLog; + +public interface ShortTermLogHistoryService extends JpaRepository<ShortTermLog, Long> { + + // step three pagination + @Query("SELECT a FROM ShortTermLog a WHERE " + + "a.tagServerTime BETWEEN :startTime AND :endTime " + + "ORDER BY a.tagServerTime ASC") + Page<ShortTermLog> findAllByTagServerTimeBetweenOrderByTagServerTimeDesc( + @Param("startTime") LocalDateTime from, + @Param("endTime") LocalDateTime to, + Pageable pageable); + + // step one unique tags + + @Query("SELECT DISTINCT a.id FROM ShortTermLog a WHERE " + + "a.tagServerTime BETWEEN :startTime AND :endTime ") + List<Long> findDistinctIdByTagTimeBetween( + @Param("startTime") LocalDateTime startTime, + @Param("endTime") LocalDateTime endTime); +} diff --git a/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/ShortTermLogHistoryService.java~HEAD b/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/ShortTermLogHistoryService.java~HEAD new file mode 100644 index 0000000000000000000000000000000000000000..510b8b0bf467a35e1a6a8aacb7368e2c2c447436 --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/ShortTermLogHistoryService.java~HEAD @@ -0,0 +1,32 @@ +package cern.c2mon.client.ext.history.es_publisher.repo; + +import java.time.Instant; +import java.util.List; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import cern.c2mon.client.ext.history.es_publisher.entity.ShortTermLog; + +public interface ShortTermLogHistoryService extends JpaRepository<ShortTermLog, Long> { + + // step three pagination + @Query("SELECT a FROM ShortTermLog a WHERE " + + "a.tagServerTime BETWEEN :startTime AND :endTime " + + "ORDER BY a.tagServerTime ASC") + Page<ShortTermLog> findAllByTagServerTimeBetween( + @Param("startTime") Instant from, + @Param("endTime") Instant to, + Pageable pageable); + + // step one unique tags + + @Query("SELECT DISTINCT a.id FROM ShortTermLog a WHERE " + + "a.tagServerTime BETWEEN :startTime AND :endTime ") + List<Long> findDistinctIdByTagTimeBetween( + @Param("startTime") Instant startTime, + @Param("endTime") Instant endTime); +} diff --git a/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/TagConfigHistoryService.java b/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/TagConfigHistoryService.java new file mode 100644 index 0000000000000000000000000000000000000000..47c2307f761c06bddf5464e148c54600b3dd7c8c --- /dev/null +++ b/src/main/java/cern/c2mon/client/ext/history/es_publisher/repo/TagConfigHistoryService.java @@ -0,0 +1,21 @@ +package cern.c2mon.client.ext.history.es_publisher.repo; + +import java.time.LocalDateTime; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; + +import cern.c2mon.client.ext.history.es_publisher.DataTagData; +import cern.c2mon.client.ext.history.laser.AlarmShorttermlog; + +public interface TagConfigHistoryService extends JpaRepository<DataTagData, Long>{ + + Page<AlarmShorttermlog> findAllBetweenByOrderByTagTimeStampDesc( + @Param("startTime") LocalDateTime startTime, + @Param("endTime") LocalDateTime endTime, + Pageable pageable); + + Page<DataTagData> findAllByOrderByTagTimeStampDesc(Pageable pageable); +} diff --git a/src/main/java/cern/c2mon/client/ext/history/laser/repo/AlarmShorttermlogHistoryService.java b/src/main/java/cern/c2mon/client/ext/history/laser/repo/AlarmShorttermlogHistoryService.java index a47ca59b72cc9e37408a807274c6a2d16b4838d1..e966b605fb4019b9efed220df763fe4ceb1a990f 100644 --- a/src/main/java/cern/c2mon/client/ext/history/laser/repo/AlarmShorttermlogHistoryService.java +++ b/src/main/java/cern/c2mon/client/ext/history/laser/repo/AlarmShorttermlogHistoryService.java @@ -2,6 +2,7 @@ package cern.c2mon.client.ext.history.laser.repo; import cern.c2mon.client.ext.history.laser.AlarmShorttermlog; +import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.List; @@ -51,4 +52,5 @@ public interface AlarmShorttermlogHistoryService extends JpaRepository<AlarmShor @Param("id") Long id, Pageable pageable); + } diff --git a/src/main/java/cern/c2mon/client/ext/history/supervision/ServerSupervisionEvent.java b/src/main/java/cern/c2mon/client/ext/history/supervision/ServerSupervisionEvent.java index e575bf6d31f927e30d62da7a34e3f711e4a38a2d..e4825c7e1778b05295dabd3e57735c9ec585dd35 100644 --- a/src/main/java/cern/c2mon/client/ext/history/supervision/ServerSupervisionEvent.java +++ b/src/main/java/cern/c2mon/client/ext/history/supervision/ServerSupervisionEvent.java @@ -1,15 +1,26 @@ package cern.c2mon.client.ext.history.supervision; - +import cern.c2mon.client.ext.history.equipment.EquipmentRecord; +import cern.c2mon.client.ext.history.process.Process; import lombok.Data; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; import javax.persistence.Table; + +import java.time.Instant; import java.time.LocalDateTime; +import org.hibernate.annotations.NotFound; +import org.hibernate.annotations.NotFoundAction; + /** * @author Manuel Bouzas Reguera */ @@ -29,6 +40,8 @@ public class ServerSupervisionEvent { @Column(name = "SUL_DATE") private LocalDateTime eventTime; + @Column(name = "SUL_DATE", insertable = false, updatable = false) + private Instant eventInstant; @Column(name = "SUL_STATUS") private String status; @@ -37,5 +50,13 @@ public class ServerSupervisionEvent { @Column(name = "SUL_MESSAGE") private String sul_message; + @ManyToOne + @JoinColumn(name = "sul_id") + @NotFound(action = NotFoundAction.IGNORE) + private EquipmentRecord equipmentRecord; + @ManyToOne + @JoinColumn(name = "sul_id", insertable = false, updatable = false) + @NotFound(action = NotFoundAction.IGNORE) + private Process process; } diff --git a/src/main/java/cern/c2mon/client/ext/history/supervision/SupervisionEventRepository.java b/src/main/java/cern/c2mon/client/ext/history/supervision/SupervisionEventRepository.java index a077f2b4d2c3407bfd456597f4697a66e62edec4..7c3199df145ed3b8e5b761d8993a6e8c0cf9c801 100644 --- a/src/main/java/cern/c2mon/client/ext/history/supervision/SupervisionEventRepository.java +++ b/src/main/java/cern/c2mon/client/ext/history/supervision/SupervisionEventRepository.java @@ -1,7 +1,9 @@ package cern.c2mon.client.ext.history.supervision; +import java.time.Instant; import java.time.LocalDateTime; import java.util.List; +import java.util.Set; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -18,4 +20,6 @@ public interface SupervisionEventRepository extends JpaRepository<ServerSupervis Page<ServerSupervisionEvent> findAllDistinctByIdOrderByEventTimeDesc(Long id, Pageable pageable); + Set<ServerSupervisionEvent> findByEventInstantBetween(Instant from, Instant to); + }