-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
14 changed files
with
468 additions
and
11 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
it/src/main/scala/org/mbari/oni/endpoints/HistoryEndpointsSuite.scala
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
54 changes: 54 additions & 0 deletions
54
oni/src/main/java/org/mbari/oni/jpa/repositories/PrefNodeRepository.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,54 @@ | ||
/* | ||
* Copyright (c) Monterey Bay Aquarium Research Institute 2024 | ||
* | ||
* oni code is non-public software. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. Proprietary and confidential. | ||
*/ | ||
|
||
package org.mbari.oni.jpa.repositories; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import org.mbari.oni.jpa.entities.PreferenceNodeEntity; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class PrefNodeRepository extends Repository { | ||
|
||
public PrefNodeRepository(EntityManager entityManager) { | ||
super(entityManager); | ||
} | ||
|
||
public Optional<PreferenceNodeEntity> findByNodeNameAndPrefKey(String name, String key) { | ||
return findByNamedQuery("PreferenceNode.findByNodeNameAndPrefKey", Map.of("nodeName", name, "prefKey", key)) | ||
.stream() | ||
.findFirst(); | ||
} | ||
|
||
public PreferenceNodeEntity create(String name, String key, String value) { | ||
var prefNode = new PreferenceNodeEntity(); | ||
prefNode.setName(name); | ||
prefNode.setKey(key); | ||
prefNode.setValue(value); | ||
return entityManager.persist(prefNode); | ||
} | ||
|
||
public Optional<PreferenceNodeEntity> update(String name, String key, String value) { | ||
var prefNode = findByNodeNameAndPrefKey(name, key); | ||
prefNode.setValue(value); | ||
return entityManager.merge(prefNode); | ||
} | ||
|
||
public void delete(String name, String key) { | ||
var opt = findByNodeNameAndPrefKey(name, key); | ||
opt.ifPresent(prefNode -> entityManager.remove(prefNode)); | ||
} | ||
|
||
public List<PreferenceNodeEntity> findByNodeName(String name) { | ||
return findByNamedQuery("PreferenceNode.findAllByNodeName", Map.of("nodeName", name)); | ||
} | ||
|
||
public List<PreferenceNodeEntity> findByNodeNameLike(String name) { | ||
return findByNamedQuery("PreferenceNode.findAllLikeNodeName", Map.of("nodeName", name + '%')); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) Monterey Bay Aquarium Research Institute 2024 | ||
* | ||
* oni code is non-public software. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. Proprietary and confidential. | ||
*/ | ||
|
||
package org.mbari.oni.domain | ||
|
||
import org.mbari.oni.jpa.entities.PreferenceNodeEntity | ||
|
||
case class PrefNode(name: String, key: String, value: String): | ||
def toEntity: PreferenceNodeEntity = | ||
val entity = new PreferenceNodeEntity() | ||
entity.setNodeName(name) | ||
entity.setPrefKey(key) | ||
entity.setPrefValue(value) | ||
entity | ||
|
||
object PrefNode: | ||
def from(entity: PreferenceNodeEntity): PrefNode = PrefNode( | ||
entity.getNodeName, | ||
entity.getPrefKey, | ||
entity.getPrefValue | ||
) |
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,59 @@ | ||
/* | ||
* Copyright (c) Monterey Bay Aquarium Research Institute 2024 | ||
* | ||
* oni code is non-public software. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. Proprietary and confidential. | ||
*/ | ||
|
||
package org.mbari.oni.domain | ||
|
||
import org.jasypt.util.password.BasicPasswordEncryptor | ||
import org.mbari.oni.jpa.entities.UserAccountEntity | ||
import org.mbari.oni.etc.jdk.Numbers.given | ||
|
||
case class UserAccount( | ||
username: String, | ||
password: String, | ||
role: String = "ReadOnly", | ||
affiliation: Option[String] = None, | ||
firstName: Option[String] = None, | ||
lastName: Option[String] = None, | ||
email: Option[String] = None, | ||
id: Option[Long] = None, | ||
isEncrypted: Option[Boolean] = None | ||
) { | ||
|
||
def toEntity: UserAccountEntity = { | ||
val entity = new UserAccountEntity() | ||
entity.setUserName(username) | ||
// If the password is not encrypted, then encrypt it | ||
if (isEncrypted.getOrElse(false)) | ||
entity.setEncryptedPassword(password) | ||
else | ||
entity.setPassword(password) | ||
entity.setRole(role) | ||
entity.setAffiliation(affiliation.orNull) | ||
entity.setFirstName(firstName.orNull) | ||
entity.setLastName(lastName.orNull) | ||
entity.setEmail(email.orNull) | ||
entity.setId(id.map(_.asInstanceOf[java.lang.Long]).orNull) | ||
entity | ||
} | ||
|
||
} | ||
|
||
object UserAccount { | ||
|
||
def from(userAccount: UserAccountEntity): UserAccount = UserAccount( | ||
userAccount.getUserName, | ||
userAccount.getEncryptedPassword, | ||
userAccount.getRole, | ||
Option(userAccount.getAffiliation), | ||
Option(userAccount.getFirstName), | ||
Option(userAccount.getLastName), | ||
Option(userAccount.getEmail), | ||
Option(userAccount.getPrimaryKey).map(_.asInstanceOf[Long]), | ||
Some(true) | ||
) | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
oni/src/main/scala/org/mbari/oni/domain/UserAccountUpdate.scala
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,20 @@ | ||
/* | ||
* Copyright (c) Monterey Bay Aquarium Research Institute 2024 | ||
* | ||
* oni code is non-public software. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. Proprietary and confidential. | ||
*/ | ||
|
||
package org.mbari.oni.domain | ||
|
||
case class UserAccountUpdate(username: String, | ||
password: Option[String] = None, | ||
role: Option[String] = None, | ||
affiliation: Option[String] = None, | ||
firstName: Option[String] = None, | ||
lastName: Option[String] = None, | ||
email: Option[String] = None, | ||
) { | ||
|
||
|
||
} |
7 changes: 7 additions & 0 deletions
7
oni/src/main/scala/org/mbari/oni/endpoints/HistoryEndpoints.scala
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
91 changes: 91 additions & 0 deletions
91
oni/src/main/scala/org/mbari/oni/endpoints/LinkEndpoints.scala
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,91 @@ | ||
/* | ||
* Copyright (c) Monterey Bay Aquarium Research Institute 2024 | ||
* | ||
* oni code is non-public software. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. Proprietary and confidential. | ||
*/ | ||
|
||
package org.mbari.oni.endpoints | ||
|
||
import jakarta.persistence.EntityManagerFactory | ||
import org.mbari.oni.domain.{ErrorMsg, Link} | ||
import org.mbari.oni.services.LinkService | ||
import sttp.tapir.* | ||
import sttp.tapir.Endpoint | ||
import sttp.tapir.json.circe.* | ||
import sttp.tapir.server.ServerEndpoint | ||
import sttp.tapir.server.nima.Id | ||
import org.mbari.oni.etc.circe.CirceCodecs.given | ||
|
||
class LinkEndpoints(entityManagerFactory: EntityManagerFactory) extends Endpoints { | ||
|
||
private val service = LinkService(entityManagerFactory) | ||
private val base = "links" | ||
private val tag = "Links" | ||
// get all links | ||
|
||
val allLinksEndpoint: Endpoint[Unit, Unit, ErrorMsg, Seq[Link], Any] = openEndpoint | ||
.get | ||
.in(base) | ||
.out(jsonBody[Seq[Link]]) | ||
.name("links") | ||
.description("Get all links") | ||
.tag(tag) | ||
|
||
val allLinksEndpointImpl: ServerEndpoint[Any, Id] = allLinksEndpoint.serverLogic { | ||
_ => handleErrors(service.findAllLinkTemplates()) | ||
} | ||
|
||
// get links for a concept | ||
val linksForConceptEndpoint: Endpoint[Unit, String, ErrorMsg, Seq[Link], Any] = openEndpoint | ||
.get | ||
.in(base / path[String]("name")) | ||
.out(jsonBody[Seq[Link]]) | ||
.name("linksForConcept") | ||
.description("Get all link templates applicable to a concept") | ||
.tag(tag) | ||
|
||
val linksForConceptEndpointImpl: ServerEndpoint[Any, Id] = linksForConceptEndpoint.serverLogic { name => | ||
handleErrors(service.findAllLinkTemplatesForConcept(name)) | ||
} | ||
|
||
// get links for a concept and linkname | ||
val linksForConceptAndLinkNameEndpoint: Endpoint[Unit, (String, String), ErrorMsg, Seq[Link], Any] = openEndpoint | ||
.get | ||
.in(base / path[String]("name") / "using" / path[String]("linkName")) | ||
.out(jsonBody[Seq[Link]]) | ||
.name("linksForConceptAndLinkName") | ||
.description("Get all link templates applicable to a concept and link name") | ||
.tag(tag) | ||
|
||
val linksForConceptAndLinkNameEndpointImpl: ServerEndpoint[Any, Id] = linksForConceptAndLinkNameEndpoint.serverLogic { (name, linkName) => | ||
handleErrors(service.findLinkTemplatesByNameForConcept(name, linkName)) | ||
} | ||
|
||
// get link realizations for a concept | ||
val linkRealizationsEndpoint: Endpoint[Unit, String, ErrorMsg, Seq[Link], Any] = openEndpoint | ||
.get | ||
.in(base / "query" / "linkrealizations" / path[String]("linkName")) | ||
.out(jsonBody[Seq[Link]]) | ||
.name("linkRealizations") | ||
.description("Get all link realizations for a link name") | ||
.tag(tag) | ||
|
||
val linkRealizationsEndpointImpl: ServerEndpoint[Any, Id] = linkRealizationsEndpoint.serverLogic { linkName => | ||
handleErrors(service.findLinkRealizationsByLinkName(linkName)) | ||
} | ||
|
||
override def all: List[Endpoint[_, _, _, _, _]] = List ( | ||
linkRealizationsEndpoint, | ||
linksForConceptAndLinkNameEndpoint, | ||
linksForConceptEndpoint, // TODO verify this order works | ||
allLinksEndpoint, | ||
) | ||
|
||
override def allImpl: List[ServerEndpoint[Any, Id]] = List( | ||
linkRealizationsEndpointImpl, | ||
linksForConceptAndLinkNameEndpointImpl, | ||
linksForConceptEndpointImpl, | ||
allLinksEndpointImpl, | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
oni/src/main/scala/org/mbari/oni/endpoints/RawEndpoints.scala
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,12 @@ | ||
/* | ||
* Copyright (c) Monterey Bay Aquarium Research Institute 2024 | ||
* | ||
* oni code is non-public software. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. Proprietary and confidential. | ||
*/ | ||
|
||
package org.mbari.oni.endpoints | ||
|
||
class RawEndpoints { | ||
|
||
} |
Oops, something went wrong.