Skip to content

Commit

Permalink
feat: add project metadata and related handling #3476 (#3584)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgomer2001 committed Jan 10, 2023
1 parent 25ee0af commit b95e53e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.jans.ads;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.jans.ads.model.Deployment;
import io.jans.ads.model.DeploymentDetails;
import io.jans.ads.model.ProjectMetadata;
import io.jans.agama.dsl.TranspilationResult;
import io.jans.agama.dsl.Transpiler;
import io.jans.agama.dsl.TranspilerException;
Expand Down Expand Up @@ -62,6 +65,10 @@ public class Deployer {
private static final String[] ASSETS_SUBDIRS = { "ftl", "fl" };
private static final String[] TEMPLATES_EXTENSIONS = new String[] { "ftl", "ftlh" };
private static final String FLOW_EXT = "flow";
private static final String METADATA_FILE = "project.json";

@Inject
private ObjectMapper mapper;

@Inject
private Logger logger;
Expand Down Expand Up @@ -98,7 +105,8 @@ public void process() throws IOException {
if (deployment == null) {
updateFlowsAndAssets(depls);
} else {
deployProject(deployment.getDn(), deployment.getId(), deployment.getDetails().getProjectName());
deployProject(deployment.getDn(), deployment.getId(),
deployment.getDetails().getProjectMetadata().getProjectName());
}

}
Expand All @@ -107,7 +115,6 @@ private void deployProject(String dn, String prjId, String name) throws IOExcept

logger.info("Deploying project {}", name);
DeploymentDetails dd = new DeploymentDetails();
dd.setProjectName(name);

Deployment dep = entryManager.find(dn, Deployment.class, null);
String b64EncodedAssets = dep.getAssets();
Expand All @@ -121,7 +128,9 @@ private void deployProject(String dn, String prjId, String name) throws IOExcept

//Check the zip has the expected layout
Path p = extractGamaFile(b64EncodedAssets);
String tmpdir = p.toString();
String tmpdir = p.toString();
dd.setProjectMetadata(computeMetadata(name, tmpdir));

Path pcode = Paths.get(tmpdir, "code");
Path pweb = Paths.get(tmpdir, "web");

Expand Down Expand Up @@ -156,7 +165,7 @@ private void deployProject(String dn, String prjId, String name) throws IOExcept
logger.warn("This does not seem to be a .gama file");
dd.setError("Archive missing web and/or code subdirectories");
}

dep.setDetails(dd);
//Mark as finished
dep.setTaskActive(false);
Expand Down Expand Up @@ -320,7 +329,7 @@ private void updateFlowsAndAssets(List<Deployment> deployments) {
//In this case d only has id, start date, and end date populated
String prjId = d.getId();
actualPrjIds.add(prjId);
String name = d.getDetails().getProjectName();
String name = d.getDetails().getProjectMetadata().getProjectName();

Long finishedAt = projectsFinishTimes.get(prjId);

Expand Down Expand Up @@ -402,6 +411,25 @@ private void removeFlows(Set<String> flows) {
}

}

private ProjectMetadata computeMetadata(String name, String path) {

ProjectMetadata meta = new ProjectMetadata();
Path p = Paths.get(path, METADATA_FILE);

if (!Files.isRegularFile(p)) {
logger.warn("Archive has no metadata file");
} else {
try {
meta = mapper.readValue(Files.readString(p, UTF_8), ProjectMetadata.class);
} catch (IOException e) {
logger.error("Unable to read archive metadata", e);
}
}
meta.setProjectName(name);
return meta;

}

private static String dnFromQname(String qname) {
return String.format("%s=%s,%s", Flow.ATTR_NAMES.QNAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class DeploymentDetails {

private String projectName;
private List<String> folders;
private Map<String, String> flowsError;
private String error;

public String getProjectName() {
return projectName;
private ProjectMetadata metadata = new ProjectMetadata();

public ProjectMetadata getProjectMetadata() {
return metadata;
}

public void setProjectName(String projectName) {
this.projectName = projectName;
public void setProjectMetadata(ProjectMetadata metadata) {
this.metadata = metadata;
}

public List<String> getFolders() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.jans.ads.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ProjectMetadata {

private String projectName;
private String author;
private String type;
private String description;

public String getProjectName() {
return projectName;
}

public void setProjectName(String projectName) {
this.projectName = projectName;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean createDeploymentTask(String name, byte[] gamaBinary) {
}

DeploymentDetails dd = new DeploymentDetails();
dd.setProjectName(name);
dd.getProjectMetadata().setProjectName(name);

if (!existing) {
d = new Deployment();
Expand Down

0 comments on commit b95e53e

Please sign in to comment.