Skip to content

Commit

Permalink
Initial refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgarde committed Jul 7, 2023
1 parent 1c0f278 commit 1e61f92
Show file tree
Hide file tree
Showing 58 changed files with 1,531 additions and 391 deletions.
14 changes: 3 additions & 11 deletions database/local_data.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
-- Data for testing locally
-- *** DO NOT DEPLOY TO UAT OR OPS ***

INSERT INTO "Users" ("id", "username") VALUES ('fee1dc78-0604-4fa6-adae-0b4b55440e7d', '[email protected]');

INSERT INTO "RasterDefinitions" (
"outputGranuleExtentFlag", "outputSamplingGridType", "rasterResolution", "utmZoneAdjust", "mgrsBandAdjust"
) VALUES (
TRUE, 'UTM', 1000, 1, -1
);

INSERT INTO "RasterDefinitions" (
"outputGranuleExtentFlag", "outputSamplingGridType", "rasterResolution"
INSERT INTO "Users" (
"id", "username", "email", "firstName", "lastName"
) VALUES (
TRUE, 'GEO', 3
'fee1dc78-0604-4fa6-adae-0b4b55440e7d', 'test-user', 'test@localhost', 'First', 'Last'
);
40 changes: 29 additions & 11 deletions database/schema.sql
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
-- Create tables
CREATE TABLE "Users" (
"id" uuid DEFAULT gen_random_uuid() PRIMARY KEY,
"username" varchar UNIQUE NOT NULL
"username" varchar UNIQUE NOT NULL,
"email" varchar NOT NULL,
"firstName" varchar NOT NULL,
"lastName" varchar NOT NULL
);

CREATE TABLE "RasterDefinitions" (
"id" uuid DEFAULT gen_random_uuid() PRIMARY KEY,
"userId" uuid NOT NULL,
"name" varchar NOT NULL,
"outputGranuleExtentFlag" boolean NOT NULL,
"outputSamplingGridType" varchar NOT NULL,
"rasterResolution" int NOT NULL,
"utmZoneAdjust" int,
"mgrsBandAdjust" int
"mgrsBandAdjust" int,
FOREIGN KEY ("userId") REFERENCES "Users" ("id")
);

CREATE TABLE "L2RasterProducts" (
"id" uuid DEFAULT gen_random_uuid() PRIMARY KEY,
"definitionID" uuid NOT NULL,
"timestamp" timestamp with time zone NOT NULL DEFAULT current_timestamp,
"cycle" int NOT NULL,
"pass" int NOT NULL,
"scene" int NOT NULL,
FOREIGN KEY ("definitionID") REFERENCES "RasterDefinitions" ("id")
"outputGranuleExtentFlag" boolean NOT NULL,
"outputSamplingGridType" varchar NOT NULL,
"rasterResolution" int NOT NULL,
"utmZoneAdjust" int,
"mgrsBandAdjust" int
);

CREATE TABLE "Granules" (
"id" uuid DEFAULT gen_random_uuid() PRIMARY KEY,
"productId" uuid NOT NULL,
"timestamp" timestamp with time zone NOT NULL DEFAULT current_timestamp,
"uri" varchar NOT NULL,
FOREIGN KEY ("productId") REFERENCES "L2RasterProducts" ("id")
);

CREATE TABLE "ProductHistory" (
"requestedByID" uuid,
"rasterProductID" uuid,
"requestedById" uuid,
"rasterProductId" uuid,
"timestamp" timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY ("requestedByID", "rasterProductID"),
FOREIGN KEY ("requestedByID") REFERENCES "Users" ("id"),
FOREIGN KEY ("rasterProductID") REFERENCES "L2RasterProducts" ("id") ON DELETE CASCADE
PRIMARY KEY ("requestedById", "rasterProductId"),
FOREIGN KEY ("requestedById") REFERENCES "Users" ("id"),
FOREIGN KEY ("rasterProductId") REFERENCES "L2RasterProducts" ("id") ON DELETE CASCADE
);

CREATE TABLE "Status" (
"id" uuid DEFAULT gen_random_uuid() PRIMARY KEY,
"productID" uuid NOT NULL,
"productId" uuid NOT NULL,
"timestamp" timestamp with time zone NOT NULL DEFAULT current_timestamp,
"state" varchar NOT NULL,
"reason" text,
FOREIGN KEY ("productID") REFERENCES "L2RasterProducts" ("id") ON DELETE CASCADE
FOREIGN KEY ("productId") REFERENCES "L2RasterProducts" ("id") ON DELETE CASCADE
);
12 changes: 12 additions & 0 deletions src/main/java/gov/nasa/podaac/swodlr/SwodlrProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gov.nasa.podaac.swodlr;

import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;

@ConfigurationProperties("swodlr")
@ConstructorBinding
public record SwodlrProperties(
Map<String, String> teaMapping,
String productCreateQueueUrl
) { }
3 changes: 0 additions & 3 deletions src/main/java/gov/nasa/podaac/swodlr/Utils.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package gov.nasa.podaac.swodlr;

import java.util.UUID;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class Utils implements ApplicationContextAware {
public static final UUID NULL_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");

private static ApplicationContext applicationContext;

@Override
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/gov/nasa/podaac/swodlr/granule/Granule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package gov.nasa.podaac.swodlr.granule;

import com.fasterxml.jackson.annotation.JsonIgnore;
import gov.nasa.podaac.swodlr.Utils;
import gov.nasa.podaac.swodlr.l2rasterproduct.L2RasterProduct;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalDateTime;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.validator.constraints.URL;

@Entity
@Table(name = "Granules")
public class Granule {
@Id
private UUID id;

@ManyToOne(optional = false)
@JoinColumn(name = "productId", nullable = false)
private L2RasterProduct product;

@Column(nullable = false)
private LocalDateTime timestamp;

@Column(nullable = false)
private String uri;

Granule() { }

public Granule(L2RasterProduct product, String uri) {
this.id = UUID.randomUUID();
this.timestamp = LocalDateTime.now();
this.product = product;
this.uri = uri;
}

public UUID getId() {
return id;
}

public L2RasterProduct getProduct() {
return product;
}

public LocalDateTime getTimestamp() {
return timestamp;
}

@JsonIgnore
public String getS3Uri() {
return uri;
}

public String getUri() {
try {
return Utils
.applicationContext()
.getBean(TeaMapper.class)
.convertS3Uri(URI.create(uri))
.toString();
} catch (URISyntaxException ex) { }

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gov.nasa.podaac.swodlr.granule;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.data.method.annotation.SchemaMapping;
import org.springframework.stereotype.Controller;
import gov.nasa.podaac.swodlr.l2rasterproduct.L2RasterProduct;

@Controller
public class GranuleController {
@Autowired
private GranuleRepository granuleRepository;

@SchemaMapping(typeName = "L2RasterProduct", field = "granules")
public Set<Granule> getGranulesForProduct(L2RasterProduct product) {
return granuleRepository.findByProduct(product);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gov.nasa.podaac.swodlr.granule;

import gov.nasa.podaac.swodlr.l2rasterproduct.L2RasterProduct;
import java.util.Set;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;

public interface GranuleRepository extends JpaRepository<Granule, UUID> {
Set<Granule> findByProduct(L2RasterProduct product);
}
22 changes: 22 additions & 0 deletions src/main/java/gov/nasa/podaac/swodlr/granule/TeaMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gov.nasa.podaac.swodlr.granule;

import gov.nasa.podaac.swodlr.SwodlrProperties;
import java.net.URI;
import java.net.URISyntaxException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TeaMapper {
@Autowired
private SwodlrProperties swodlrProperties;

public URI convertS3Uri(URI s3Uri) throws URISyntaxException{
String bucketName = s3Uri.getAuthority();
String teaHost = swodlrProperties.teaMapping().get(bucketName);
String path = "/" + bucketName + s3Uri.getPath();

URI teaUri = new URI("https", teaHost, path, null);
return teaUri;
}
}
Loading

0 comments on commit 1e61f92

Please sign in to comment.