Search in sources :

Example 1 with ConfigurationSettings

use of org.jbei.ice.lib.config.ConfigurationSettings in project ice by JBEI.

the class SampleResource method getRequestConfiguration.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/requests/settings")
public Response getRequestConfiguration() {
    String userId = getUserId();
    ConfigurationSettings settings = new ConfigurationSettings();
    return super.respond(settings.getSampleRequestSettings(userId));
}
Also used : ConfigurationSettings(org.jbei.ice.lib.config.ConfigurationSettings)

Example 2 with ConfigurationSettings

use of org.jbei.ice.lib.config.ConfigurationSettings in project ice by JBEI.

the class Utils method getConfigValue.

public static String getConfigValue(ConfigurationKey key) {
    ConfigurationSettings controller = new ConfigurationSettings();
    String value = controller.getPropertyValue(key);
    if (value != null)
        return value;
    return key.getDefaultValue();
}
Also used : ConfigurationSettings(org.jbei.ice.lib.config.ConfigurationSettings)

Example 3 with ConfigurationSettings

use of org.jbei.ice.lib.config.ConfigurationSettings in project ice by JBEI.

the class PartSequence method parseSequenceFile.

/**
 * Parses a sequence in a file and associates it with the current entry
 *
 * @param inputStream      input stream of bytes representing the file
 * @param fileName         name of file being parsed
 * @param extractHierarchy for SBOL2 sequences only. If set to <code>true</code>, creates a hierarchy of ICE entries
 *                         as needed
 * @return wrapper around the internal model used to represent sequence information
 * @throws IOException on Exception parsing the contents of the file
 */
public SequenceInfo parseSequenceFile(InputStream inputStream, String fileName, boolean extractHierarchy) throws IOException {
    AbstractParser parser;
    // write sequence file to disk (tmp)
    String tmpDir = new ConfigurationSettings().getPropertyValue(ConfigurationKey.TEMPORARY_DIRECTORY);
    if (StringUtils.isEmpty(tmpDir))
        throw new IllegalArgumentException("Cannot parse sequence without valid tmp directory");
    Path tmpPath = Paths.get(tmpDir);
    if (!Files.isDirectory(tmpPath) || !Files.isWritable(tmpPath))
        throw new IllegalArgumentException("Cannot write to tmp directory: " + tmpPath.toString());
    Path sequencePath = Paths.get(tmpPath.toString(), UUID.randomUUID().toString() + "-" + fileName);
    Files.copy(inputStream, sequencePath, StandardCopyOption.REPLACE_EXISTING);
    // detect sequence
    SequenceFormat format;
    try (InputStream fileInputStream = Files.newInputStream(sequencePath);
        LineIterator iterator = IOUtils.lineIterator(fileInputStream, StandardCharsets.UTF_8)) {
        if (!iterator.hasNext())
            throw new IOException("Cannot read stream for " + fileName);
        String firstLine = iterator.next();
        format = SequenceUtil.detectFormat(firstLine);
    }
    // special handling for sbol format
    try {
        if (format == SBOL2) {
            SBOLParser sbolParser = new SBOLParser(this.userId, Long.toString(this.entry.getId()), extractHierarchy);
            return sbolParser.parseToEntry(Files.newInputStream(sequencePath), fileName);
        }
        switch(format) {
            case GENBANK:
                parser = new GenBankParser();
                break;
            case FASTA:
                parser = new FastaParser();
                break;
            default:
            case PLAIN:
                parser = new PlainParser();
                break;
        }
        LineIterator iterator = IOUtils.lineIterator(Files.newInputStream(sequencePath), StandardCharsets.UTF_8);
        SequenceFile sequenceFile = new SequenceFile();
        String entryType = this.entry.getRecordType();
        // special handling for SBOL (todo: clean this up in future release)
        FeaturedDNASequence dnaSequence = parser.parse(iterator, entryType);
        Sequence sequence = SequenceUtil.dnaSequenceToSequence(dnaSequence);
        if (sequence == null)
            throw new IOException("Could not create sequence object");
        // copy original sequence file to file system
        try {
            Files.copy(sequencePath, sequenceFile.getFilePath(), StandardCopyOption.REPLACE_EXISTING);
            sequence.setSequenceUser(sequenceFile.getFileName());
        } catch (Exception e) {
            // ok to ignore. Can get back sequence as long as sequence object is saved. cannot download original
            Logger.warn("Exception writing sequence to file: " + e.getMessage());
        }
        sequence.setFileName(fileName);
        sequence.setFormat(format);
        sequence = saveSequenceObject(sequence);
        SequenceInfo info = sequence.toDataTransferObject();
        info.setSequence(dnaSequence);
        return info;
    } catch (InvalidFormatParserException ifpe) {
        Logger.error(ifpe);
        return null;
    } finally {
        Files.deleteIfExists(sequencePath);
    }
}
Also used : Path(java.nio.file.Path) AbstractParser(org.jbei.ice.lib.parsers.AbstractParser) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) InputStream(java.io.InputStream) IOException(java.io.IOException) FastaParser(org.jbei.ice.lib.parsers.fasta.FastaParser) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) LineIterator(org.apache.commons.io.LineIterator) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) IOException(java.io.IOException) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) GenBankParser(org.jbei.ice.lib.parsers.genbank.GenBankParser) SBOLParser(org.jbei.ice.lib.parsers.sbol.SBOLParser) PlainParser(org.jbei.ice.lib.parsers.PlainParser) ConfigurationSettings(org.jbei.ice.lib.config.ConfigurationSettings)

Example 4 with ConfigurationSettings

use of org.jbei.ice.lib.config.ConfigurationSettings in project ice by JBEI.

the class FileResource method getAsset.

@GET
@Path("asset/{assetName}")
public Response getAsset(@PathParam("assetName") final String assetName) {
    ConfigurationSettings settings = new ConfigurationSettings();
    File assetFile = settings.getUIAsset(assetName);
    if (assetFile == null)
        return super.respond(Response.Status.NOT_FOUND);
    return addHeaders(Response.ok(assetFile), assetFile.getName());
}
Also used : ConfigurationSettings(org.jbei.ice.lib.config.ConfigurationSettings) File(java.io.File)

Example 5 with ConfigurationSettings

use of org.jbei.ice.lib.config.ConfigurationSettings in project ice by JBEI.

the class ApplicationInitialize method startUp.

/**
 * Responsible for initializing the system and checking for the existence of needed
 * data (such as settings) and creating as needed
 */
public static void startUp() {
    IceExecutorService.getInstance().startService();
    // check for and create public group
    GroupController groupController = new GroupController();
    groupController.createOrRetrievePublicGroup();
    // check for and create admin account
    AccountController accountController = new AccountController();
    accountController.createAdminAccount();
    // check for and create default settings
    ConfigurationSettings settings = new ConfigurationSettings();
    settings.initPropertyValues();
    try {
        // check blast database exists and build if it doesn't
        RebuildBlastIndexTask task = new RebuildBlastIndexTask();
        IceExecutorService.getInstance().runTask(task);
        AutoAnnotationBlastDbBuildTask autoAnnotationBlastDbBuildTask = new AutoAnnotationBlastDbBuildTask();
        IceExecutorService.getInstance().runTask(autoAnnotationBlastDbBuildTask);
    } catch (Exception e) {
        Logger.error(e);
    }
}
Also used : GroupController(org.jbei.ice.lib.group.GroupController) ConfigurationSettings(org.jbei.ice.lib.config.ConfigurationSettings) RebuildBlastIndexTask(org.jbei.ice.lib.search.blast.RebuildBlastIndexTask) AutoAnnotationBlastDbBuildTask(org.jbei.ice.lib.entry.sequence.annotation.AutoAnnotationBlastDbBuildTask) AccountController(org.jbei.ice.lib.account.AccountController)

Aggregations

ConfigurationSettings (org.jbei.ice.lib.config.ConfigurationSettings)7 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 LineIterator (org.apache.commons.io.LineIterator)1 AccountController (org.jbei.ice.lib.account.AccountController)1 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)1 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)1 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)1 AutoAnnotationBlastDbBuildTask (org.jbei.ice.lib.entry.sequence.annotation.AutoAnnotationBlastDbBuildTask)1 Collections (org.jbei.ice.lib.folder.collection.Collections)1 GroupController (org.jbei.ice.lib.group.GroupController)1 AbstractParser (org.jbei.ice.lib.parsers.AbstractParser)1 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)1 PlainParser (org.jbei.ice.lib.parsers.PlainParser)1 FastaParser (org.jbei.ice.lib.parsers.fasta.FastaParser)1 GenBankParser (org.jbei.ice.lib.parsers.genbank.GenBankParser)1