-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02d938a
commit d12fd51
Showing
12 changed files
with
217 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ spring: | |
ai: | ||
vectorstore: | ||
cassandra: | ||
initialize-schema: true | ||
initialize-schema: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 0 additions & 141 deletions
141
.../src/main/java/com/assetvisor/marvin/persistence/adapters/PersistingLocalFileAdapter.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
...nce/src/main/java/com/assetvisor/marvin/persistence/adapters/cassandra/NoteBookEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.assetvisor.marvin.persistence.adapters.cassandra; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.cassandra.core.cql.PrimaryKeyType; | ||
import org.springframework.data.cassandra.core.mapping.Column; | ||
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; | ||
import org.springframework.data.cassandra.core.mapping.Table; | ||
|
||
@Table | ||
public class NoteBookEntry { | ||
|
||
@Id | ||
@PrimaryKeyColumn( | ||
name = "id", | ||
type = PrimaryKeyType.PARTITIONED | ||
) | ||
private UUID id; | ||
@Column( | ||
"created_date" | ||
) | ||
private Instant createdDate; | ||
@Column( | ||
"note_date" | ||
) | ||
private Instant noteDate; | ||
@Column( | ||
"note" | ||
) | ||
private String note; | ||
|
||
public NoteBookEntry() { | ||
} | ||
|
||
public NoteBookEntry(UUID id, Instant createdDate, Instant noteDate, String note) { | ||
this.id = id; | ||
this.createdDate = createdDate; | ||
this.noteDate = noteDate; | ||
this.note = note; | ||
} | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public void setId(UUID id) { | ||
this.id = id; | ||
} | ||
|
||
public Instant getCreatedDate() { | ||
return createdDate; | ||
} | ||
|
||
public void setCreatedDate(Instant createdDate) { | ||
this.createdDate = createdDate; | ||
} | ||
|
||
public Instant getNoteDate() { | ||
return noteDate; | ||
} | ||
|
||
public void setNoteDate(Instant noteDate) { | ||
this.noteDate = noteDate; | ||
} | ||
|
||
public String getNote() { | ||
return note; | ||
} | ||
|
||
public void setNote(String note) { | ||
this.note = note; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...rc/main/java/com/assetvisor/marvin/persistence/adapters/cassandra/NotebookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.assetvisor.marvin.persistence.adapters.cassandra; | ||
|
||
import java.util.UUID; | ||
import org.springframework.data.cassandra.repository.CassandraRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface NotebookRepository extends CassandraRepository<NoteBookEntry, UUID> { | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...com/assetvisor/marvin/persistence/adapters/cassandra/PersistingNotesCassandraAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.assetvisor.marvin.persistence.adapters.cassandra; | ||
|
||
import com.assetvisor.marvin.equipment.notebook.CalendarNote; | ||
import com.assetvisor.marvin.equipment.notebook.ForPersistingNotes; | ||
import jakarta.annotation.Resource; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.Comparator; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
//@Profile("cassandra") | ||
public class PersistingNotesCassandraAdapter implements ForPersistingNotes { | ||
|
||
@Resource | ||
private NotebookRepository notebookRepository; | ||
|
||
@Override | ||
public void persist(CalendarNote calendarNote) { | ||
notebookRepository.save(toNoteBookEntry(calendarNote)); | ||
} | ||
|
||
@Override | ||
public Optional<CalendarNote> getFirstOverdueAndDelete() { | ||
Optional<NoteBookEntry> first = notebookRepository.findAll().stream() | ||
.sorted(Comparator.comparing(NoteBookEntry::getNoteDate)) | ||
.filter(note -> note.getNoteDate().isBefore(LocalDateTime.now().toInstant(ZoneOffset.UTC))) | ||
.findFirst(); | ||
|
||
if(first.isPresent()) { | ||
notebookRepository.deleteById(first.get().getId()); | ||
return Optional.of(toCalendarNote(first.get())); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
private NoteBookEntry toNoteBookEntry(CalendarNote calendarNote) { | ||
return new NoteBookEntry( | ||
UUID.randomUUID(), | ||
Instant.now().atOffset(ZoneOffset.UTC).toInstant(), | ||
Instant.from(calendarNote.noteDate().atOffset(ZoneOffset.UTC).toInstant()), | ||
calendarNote.note() | ||
); | ||
} | ||
|
||
private CalendarNote toCalendarNote(NoteBookEntry noteBookEntry) { | ||
return new CalendarNote( | ||
LocalDateTime.from(noteBookEntry.getNoteDate().atOffset(ZoneOffset.UTC)), | ||
noteBookEntry.getNote() | ||
); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...main/java/com/assetvisor/marvin/persistence/adapters/file/PersistingLocalFileAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.assetvisor.marvin.persistence.adapters.file; | ||
|
||
import com.assetvisor.marvin.robot.domain.environment.EnvironmentDescription; | ||
import com.assetvisor.marvin.robot.domain.environment.ForPersistingEnvironmentDescriptions; | ||
import com.assetvisor.marvin.robot.domain.jobdescription.ForPersistingRobotDescription; | ||
import com.assetvisor.marvin.robot.domain.jobdescription.RobotDescription; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class PersistingLocalFileAdapter implements ForPersistingRobotDescription, ForPersistingEnvironmentDescriptions { | ||
|
||
private final Log LOG = LogFactory.getLog(getClass()); | ||
|
||
@Override | ||
public RobotDescription read() { | ||
String userHome = System.getProperty("user.home"); | ||
Path filePath = Paths.get(userHome, "marvin-robot.txt"); | ||
|
||
try { | ||
String content = Files.readString(filePath); | ||
LOG.info("Read robot description from file: " + filePath); | ||
return new RobotDescription(content); | ||
} catch (IOException e) { | ||
LOG.error("Error reading file: " + e.getMessage()); | ||
} | ||
return new RobotDescription(""); | ||
} | ||
|
||
@Override | ||
public List<EnvironmentDescription> load() { | ||
String userHome = System.getProperty("user.home"); | ||
Path filePath = Paths.get(userHome, "marvin-environments.txt"); | ||
|
||
try { | ||
List<String> lines = Files.readAllLines(filePath); | ||
LOG.info("Read environment descriptions from file: " + filePath); | ||
|
||
return lines.stream() | ||
.map(line -> { | ||
try { | ||
return new EnvironmentDescription(line); | ||
} catch (Exception e) { | ||
LOG.error("Error parsing line: " + line + " - " + e.getMessage()); | ||
return null; | ||
} | ||
}) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toList()); | ||
|
||
} catch (IOException e) { | ||
LOG.error("Error reading environments file: " + e.getMessage()); | ||
} | ||
|
||
return List.of(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.