Skip to content

Commit

Permalink
Broken build
Browse files Browse the repository at this point in the history
  • Loading branch information
hohonuuli committed May 16, 2024
1 parent 954898c commit 9406a26
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Monterey Bay Aquarium Research Institute
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 License for the specific language governing permissions and
* limitations under the License.
*/

package org.mbari.oni.endpoints

import org.mbari.oni.domain.ExtendedHistory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class UserAccountEntity implements Serializable, IPersistentObject {
nullable = false,
length = 50
)
String password;
String encryptedPassword;

@Column(
name = "Role",
Expand All @@ -109,7 +109,7 @@ public class UserAccountEntity implements Serializable, IPersistentObject {
String userName;

public boolean authenticate(String unencryptedPassword) {
return (new BasicPasswordEncryptor()).checkPassword(unencryptedPassword, password);
return (new BasicPasswordEncryptor()).checkPassword(unencryptedPassword, encryptedPassword);
}

@Override
Expand Down Expand Up @@ -150,8 +150,8 @@ public String getLastName() {
return lastName;
}

public String getPassword() {
return password;
public String getEncryptedPassword() {
return encryptedPassword;
}

public String getRole() {
Expand Down Expand Up @@ -202,8 +202,12 @@ public void setLastName(String lastName) {
this.lastName = lastName;
}

public void setPassword(String unencryptedPassword) {
this.password = (new BasicPasswordEncryptor()).encryptPassword(unencryptedPassword);
public void setEncryptedPassword(String encryptedPassword) {
this.encryptedPassword = encryptedPassword;
}

public void setPassword(String password) {
this.encryptedPassword = (new BasicPasswordEncryptor()).encryptPassword(password);
}

public void setRole(String role) {
Expand Down
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 + '%'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public void delete(Object object) {
entityManager.remove(object);
}

public void create(Object object) {
entityManager.persist(object);
}

public void update(Object object) {
entityManager.merge(object);
}

public <T> List<T> findByNamedQuery(String name) {
Query query = entityManager.createNamedQuery(name);
Expand All @@ -75,4 +82,6 @@ public <T> Optional<T> findByPrimaryKey(Class<T> clazz, Object primaryKey) {
}




}
1 change: 0 additions & 1 deletion oni/src/main/scala/org/mbari/oni/Endpoints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ object Endpoints:
val historyEndpoints: HistoryEndpoints = HistoryEndpoints(entityMangerFactory)
val phylogenyEndpoints: PhylogenyEndpoints = PhylogenyEndpoints(entityMangerFactory)


val authorizationEndpoints: AuthorizationEndpoints = AuthorizationEndpoints()
val healthEndpoints: HealthEndpoints = HealthEndpoints()

Expand Down
6 changes: 2 additions & 4 deletions oni/src/main/scala/org/mbari/oni/domain/ConceptMetadata.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ object ConceptMetadata:
def from(concept: ConceptEntity): ConceptMetadata =
val name = concept.getPrimaryConceptName.getName

val alternateNames = concept
.getConceptNames
val alternateNames = concept.getAlternativeConceptNames
.asScala
.filter(_.getNameType != ConceptNameTypes.PRIMARY.getType)
.toSet
.map(_.getName)
.toSet

val media = concept
.getConceptMetadata
Expand Down
25 changes: 25 additions & 0 deletions oni/src/main/scala/org/mbari/oni/domain/PrefNode.scala
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
)
59 changes: 59 additions & 0 deletions oni/src/main/scala/org/mbari/oni/domain/UserAccount.scala
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 oni/src/main/scala/org/mbari/oni/domain/UserAccountUpdate.scala
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,
) {


}
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* 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
Expand Down
91 changes: 91 additions & 0 deletions oni/src/main/scala/org/mbari/oni/endpoints/LinkEndpoints.scala
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 oni/src/main/scala/org/mbari/oni/endpoints/RawEndpoints.scala
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 {

}
Loading

0 comments on commit 9406a26

Please sign in to comment.