Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ClinicalTrialDataSourceConfig extends GSRSDataSourceConfig {
protected static final String NAME_DATA_SOURCE = PERSIST_UNIT + "DataSource";
public static final String NAME_ENTITY_MANAGER = PERSIST_UNIT + "EntityManager";
protected static final String NAME_DATA_SOURCE_PROPERTIES = PERSIST_UNIT + "DataSourceProperties";
protected static final String NAME_TRANSACTION_MANAGER = PERSIST_UNIT + "TransactionManager";
public static final String NAME_TRANSACTION_MANAGER = PERSIST_UNIT + "TransactionManager";



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Backup
// (taking out of EventListners annotation for now and until substance indexing issue resolved)
// BackupEntityProcessorListener.class
@EntityListeners({AuditingEntityListener.class, GsrsEntityProcessorListener.class, IndexerEntityListener.class})
@EntityListeners({AuditingEntityListener.class, GsrsEntityProcessorListener.class, IndexerEntityListener.class, BackupEntityProcessorListener.class})
public abstract class ClinicalTrialBase extends
AbstractGsrsTablePerClassEntity
implements FetchableEntity, ForceUpdateDirtyMakerMixin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import gsrs.repository.GsrsRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;


@Repository
@NoRepositoryBean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gov.hhs.gsrs.clinicaltrial.us.exporters;

import com.fasterxml.jackson.databind.ObjectWriter;
import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUS;
import ix.core.controllers.EntityFactory;
import ix.ginas.exporters.Exporter;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Objects;

public class JsonExporter implements Exporter<ClinicalTrialUS> {
private final BufferedWriter out;

private static final String LEADING_HEADER= "\t\t";
private final ObjectWriter writer = EntityFactory.EntityMapper.FULL_ENTITY_MAPPER().writer();

public JsonExporter(OutputStream out) throws IOException{
Objects.requireNonNull(out);
this.out = new BufferedWriter(new OutputStreamWriter(out));
}
@Override
public void export(ClinicalTrialUS obj) throws IOException {
out.write(LEADING_HEADER);
//need to write as a string because the json writer
//will sometimes close the writer depending on which implementation it is...
out.write(writer.writeValueAsString(obj));
out.newLine();
}

@Override
public void close() throws IOException {
out.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package gov.hhs.gsrs.clinicaltrial.us.exporters;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUS;
import ix.ginas.exporters.Exporter;
import ix.ginas.exporters.ExporterFactory;
import ix.ginas.exporters.OutputFormat;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Set;
import java.util.zip.GZIPOutputStream;

public class JsonExporterFactory implements ExporterFactory {

OutputFormat format = new OutputFormat("gsrs", "GSRS bulk, gzipped JSON (.gsrs)");

@Override
public boolean supports(Parameters params) {
return params.getFormat().equals(format);
}

@Override
public Set<OutputFormat> getSupportedFormats() {
return Collections.singleton(format);
}

@Override
public Exporter<ClinicalTrialUS> createNewExporter(OutputStream out, Parameters params) throws IOException {
// if(params.shouldCompress()) {
return new JsonExporter(new GZIPOutputStream(out));
// }
// return new JsonExporter(out);
}

@Override
public JsonNode getSchema() {
ObjectNode parameters = JsonNodeFactory.instance.objectNode();
parameters.put("excludedCollections", "String[]");
parameters.put("recordLimit", Integer.class.getName());
return generateSchemaNode("JSON Exporter Parameters", parameters);
}


}

Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package gov.hhs.gsrs.clinicaltrial.us.repositories;

import gov.hhs.gsrs.clinicaltrial.ClinicalTrialDataSourceConfig;
import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUS;
import gov.hhs.gsrs.clinicaltrial.base.repositories.ClinicalTrialBaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.persistence.PersistenceContext;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Stream;

@Repository
@Transactional
public interface ClinicalTrialUSRepository extends ClinicalTrialBaseRepository<ClinicalTrialUS> { }
public interface ClinicalTrialUSRepository extends ClinicalTrialBaseRepository<ClinicalTrialUS> {

@Query("select t from ClinicalTrialUS t")
public Stream<ClinicalTrialUS> streamAll();

@Query("select t.trialNumber from ClinicalTrialUS t")
List<String> getAllIds();



}


Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package gov.hhs.gsrs.clinicaltrial.us.tasks;


import gsrs.scheduledTasks.ScheduledTaskInitializer;
import gsrs.scheduledTasks.SchedulerPlugin;
import gsrs.services.BackupService;
import gsrs.springUtils.StaticContextAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;

public class ClinicalTrialUSRebackupTaskInitializer extends ScheduledTaskInitializer {
@Autowired
private BackupService backupService;

private String description;

private Class<? extends JpaRepository> repositoryClass;

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

public Class<? extends JpaRepository> getRepositoryClass() {
return repositoryClass;
}

public void setRepositoryClass(Class<? extends JpaRepository> repositoryClass) {
this.repositoryClass = repositoryClass;
}

@Override
public String getDescription() {
return description;
}


@Override
public void run(SchedulerPlugin.JobStats stats, SchedulerPlugin.TaskListener l){
backupService.reBackupAllEntitiesOfType(StaticContextAccessor.getBean(repositoryClass),
PageRequest.of(0, 200), taskProgress -> {
l.message(taskProgress.getCurrentCount() + " of " + taskProgress.getTotalCount());
});
}
}
Loading