Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

simplified Modularization #20

Open
wants to merge 1 commit into
base: GSRS_DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions app/ix/core/controllers/CoreSubstanceFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package ix.core.controllers;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import ix.core.util.CachedSupplier;
import ix.ginas.models.v1.Substance;
import ix.ginas.models.v1.SubstanceReference;
import ix.utils.UUIDUtil;
import ix.utils.Util;

import play.Logger;
import play.db.ebean.Model;

public class CoreSubstanceFactory extends EntityFactory {
private static final String CODE_TYPE_PRIMARY = "PRIMARY";
static public CachedSupplier<Model.Finder<UUID, Substance>> finder = Util.finderFor(UUID.class, Substance.class);

/**
* Get a Substance by it's UUID
* @param uuid
* @return
*/
public static Substance getSubstance(String uuid) {
if (uuid == null ||!UUIDUtil.isUUID(uuid)) {
return null;
}
return getSubstance(UUID.fromString(uuid));
}
public static Substance getSubstance(UUID uuid) {
return getEntity(uuid, finder.get());
}

public static Substance getFullSubstance(SubstanceReference subRef) {
try {
if (subRef == null)
return null;
return getSubstanceByApprovalIDOrUUID(subRef.approvalID, subRef.refuuid);
}catch(Exception e){
e.printStackTrace();
throw e;
}
}

public static List<Substance> getSubstanceWithAlternativeDefinition(Substance altSub) {
List<Substance> sublist = new ArrayList<Substance>();
sublist = finder.get().where()
.and(com.avaje.ebean.Expr.eq("relationships.relatedSubstance.refuuid",
altSub.getOrGenerateUUID().toString()),
com.avaje.ebean.Expr.eq("relationships.type", Substance.ALTERNATE_SUBSTANCE_REL)).findList();

List<Substance> realList = new ArrayList<Substance>();
for (Substance sub : sublist) {
for (SubstanceReference sref : sub.getAlternativeDefinitionReferences()) {
if (sref.refuuid.equals(altSub.getUuid().toString())) {
realList.add(sub);
break;
}
}
}
return realList;
}

/**
* Returns the substance corresponding to the supplied uuid or approvalID.
*
* If either is null, it will not be used in resolving. This method returns
* first based on the UUID, and falls back to the approvalID if nothing is
* found.
*
* @param approvalID
* @param uuid
* @return
*/
private static Substance getSubstanceByApprovalIDOrUUID(String approvalID, String uuid) {
try {
if (approvalID == null && uuid == null)
return null;
Substance s = null;

if(uuid != null){
try{
s=getSubstance(uuid);
}catch(Exception e){
e.printStackTrace();
}
}

if (s == null && approvalID != null) {
s = getSubstanceByApprovalID(approvalID);
}
return s;
} catch (Exception e) {
e.printStackTrace();
}
return null;
// return finder.where().eq("approvalID", approvalID).findUnique();
}
public static Substance getSubstanceByApprovalID(String approvalID) {
List<Substance> list = finder.get().where().ieq("approvalID", approvalID).findList();
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
}

public static List<Substance> getSubstances(int top, int skip, String filter) {
List<Substance> substances = filter(new FetchOptions(top, skip, filter), finder.get());
return substances;
}

// TODO: Doesn't support top/skip
public static List<Substance> getSubstancesWithExactName(int top, int skip, String name) {
return finder.get().where().eq("names.name", name).findList();
}

// TODO: Doesn't support top/skip
public static List<Substance> getSubstancesWithExactCode(int top, int skip, String code, String codeSystem) {
return finder.get().where(Util.andAll(
com.avaje.ebean.Expr.eq("codes.code", code),
com.avaje.ebean.Expr.eq("codes.codeSystem", codeSystem),
com.avaje.ebean.Expr.eq("codes.type", CODE_TYPE_PRIMARY)
))
.findList();
}
}
30 changes: 30 additions & 0 deletions app/ix/core/exporters/AbstractSpreadsheetFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ix.core.exporters;

import java.io.OutputStream;
import java.util.Objects;
import java.util.function.Function;

public abstract class AbstractSpreadsheetFormat extends OutputFormat {

public AbstractSpreadsheetFormat(String extension, String displayname) {
super(extension, displayname);
}

abstract Spreadsheet createSpeadsheet(OutputStream out);

public AbstractSpreadsheetFormat withInfo(Function<StringBuilder, String> extension, Function<StringBuilder, String> displayName){
Objects.requireNonNull(extension);
Objects.requireNonNull(displayName);

return newSubclass(this, extension.apply(new StringBuilder(this.getExtension())), displayName.apply(new StringBuilder(this.getDisplayName())));
}

private AbstractSpreadsheetFormat newSubclass(AbstractSpreadsheetFormat parentClass, String ext, String display){
return new AbstractSpreadsheetFormat(ext, display) {
@Override
Spreadsheet createSpeadsheet(OutputStream out) {
return parentClass.createSpeadsheet(out);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.exporters;
package ix.core.exporters;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.exporters;
package ix.core.exporters;

/**
* Created by katzelda on 8/19/16.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.exporters;
package ix.core.exporters;

/**
* Created by katzelda on 8/19/16.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.exporters;
package ix.core.exporters;

import java.io.Closeable;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.exporters;
package ix.core.exporters;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.exporters;
package ix.core.exporters;

import java.util.function.BiFunction;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.exporters;
package ix.core.exporters;

import java.io.Closeable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.exporters;
package ix.core.exporters;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ix.ginas.exporters;
package ix.core.exporters;

import ix.core.exporters.OutputFormat;
import ix.ginas.models.v1.Substance;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ix.ginas.initializers;
package ix.core.initializers;

import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import ix.core.initializers.Initializer;
import ix.core.util.IOUtil;
import ix.core.validator.ValidatorFactory;
import ix.core.validator.ValidatorPlugin;
import ix.ginas.models.v1.Substance;
import ix.ginas.utils.validation.ValidatorFactory;
import ix.ginas.utils.validation.ValidatorPlugin;
import play.Application;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.initializers;
package ix.core.initializers;

import java.io.BufferedOutputStream;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.utils;
package ix.core.utils;

/**
* An ID Generator that can generate a new ID without relying on any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.utils;
package ix.core.utils;

/**
* An ID Generator which may use properties of a given type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.utils;
package ix.core.utils;

public interface NamedIdGenerator<T, K> extends IdGeneratorForType<T,K> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ix.ginas.utils;
package ix.core.utils;

import java.util.HashSet;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package ix.ginas.utils;


package ix.core.utils;

public abstract class SequentialNumericIDGenerator<T> extends AbstractNoDependencyIDGenerator<T, String> implements NamedIdGenerator<T, String> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package ix.ginas.utils.validation;
package ix.core.validator;

import ix.core.validator.Validator;
import ix.core.util.CachedSupplier;
import ix.ginas.initializers.LoadValidatorInitializer;
import ix.core.initializers.LoadValidatorInitializer;

import java.util.LinkedHashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ix.ginas.utils.validation;
package ix.core.validator;

import ix.core.validator.Validator;
import ix.ginas.initializers.LoadValidatorInitializer;
import ix.core.initializers.LoadValidatorInitializer;

/**
* Created by katzelda on 5/7/18.
Expand Down
3 changes: 3 additions & 0 deletions modules/ginas/app/ix/ginas/controllers/GinasApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import gov.nih.ncats.molwitch.Chemical;
import gov.nih.ncats.molwitch.io.ChemFormat;
import ix.core.controllers.v1.GsrsApiUtil;
import ix.core.exporters.Exporter;
import ix.core.exporters.OutputFormat;
import ix.core.exporters.SubstanceExporterFactory;
import ix.core.exporters.SubstanceExporterFactory.Parameters;
import ix.core.validator.GinasProcessingMessage;
import ix.core.UserFetcher;
import ix.core.adapters.EntityPersistAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import ix.core.util.IOUtil;
import ix.core.exporters.OutputFormat;
import ix.ginas.exporters.SubstanceExporterFactory;
import ix.core.exporters.SubstanceExporterFactory;
import org.apache.poi.util.DefaultTempFileCreationStrategy;
import org.apache.poi.util.TempFile;
import org.apache.poi.util.TempFileCreationStrategy;
Expand Down
Loading