Search in sources :

Example 1 with Setting

use of org.jbei.ice.lib.dto.Setting in project ice by JBEI.

the class FileResource method downloadCSV.

/**
     * Extracts the csv information and writes it to the temp dir and returns the file uuid. Then
     * the client is expected to make another rest call with the uuid in a separate window. This
     * workaround is due to not being able to download files using XHR or sumsuch
     */
@POST
@Path("csv")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response downloadCSV(@QueryParam("sequenceFormats") final List<String> sequenceFormats, @QueryParam("entryFields") final List<String> fields, EntrySelection selection) {
    String userId = super.requireUserId();
    EntriesAsCSV entriesAsCSV = new EntriesAsCSV(sequenceFormats.toArray(new String[sequenceFormats.size()]));
    List<EntryField> entryFields = new ArrayList<>();
    try {
        if (fields != null) {
            entryFields.addAll(fields.stream().map(EntryField::fromString).collect(Collectors.toList()));
        }
    } catch (Exception e) {
        Logger.error(e);
    }
    boolean success = entriesAsCSV.setSelectedEntries(userId, selection, entryFields.toArray(new EntryField[entryFields.size()]));
    if (!success)
        return super.respond(false);
    final File file = entriesAsCSV.getFilePath().toFile();
    if (file.exists()) {
        return Response.ok(new Setting("key", file.getName())).build();
    }
    return Response.serverError().build();
}
Also used : Setting(org.jbei.ice.lib.dto.Setting) ArrayList(java.util.ArrayList) EntriesAsCSV(org.jbei.ice.lib.entry.EntriesAsCSV) EntryField(org.jbei.ice.lib.dto.entry.EntryField)

Example 2 with Setting

use of org.jbei.ice.lib.dto.Setting in project ice by JBEI.

the class ConfigurationController method retrieveSystemSettings.

public ArrayList<Setting> retrieveSystemSettings(String userId) {
    ArrayList<Setting> settings = new ArrayList<>();
    if (!new AccountController().isAdministrator(userId))
        return settings;
    for (ConfigurationKey key : ConfigurationKey.values()) {
        Configuration configuration = dao.get(key);
        Setting setting;
        if (configuration == null)
            setting = new Setting(key.name(), "");
        else
            setting = new Setting(configuration.getKey(), configuration.getValue());
        settings.add(setting);
    }
    return settings;
}
Also used : ConfigurationKey(org.jbei.ice.lib.dto.ConfigurationKey) Configuration(org.jbei.ice.storage.model.Configuration) Setting(org.jbei.ice.lib.dto.Setting) ArrayList(java.util.ArrayList) AccountController(org.jbei.ice.lib.account.AccountController)

Example 3 with Setting

use of org.jbei.ice.lib.dto.Setting in project ice by JBEI.

the class WebResource method getWebEntries.

@GET
@Path("/entries")
public Response getWebEntries(@QueryParam("download") boolean download, @QueryParam("limit") int limit, @QueryParam("offset") int offset) {
    String userId = requireUserId();
    log(userId, "downloading web entries");
    RemoteEntriesAsCSV remoteEntriesAsCSV = new RemoteEntriesAsCSV(true);
    remoteEntriesAsCSV.getEntries(offset, limit);
    final File file = remoteEntriesAsCSV.getFilePath().toFile();
    if (file.exists()) {
        return Response.ok(new Setting("fileName", file.getName())).build();
    }
    return super.respond(false);
}
Also used : RemoteEntriesAsCSV(org.jbei.ice.lib.net.RemoteEntriesAsCSV) Setting(org.jbei.ice.lib.dto.Setting) File(java.io.File)

Aggregations

Setting (org.jbei.ice.lib.dto.Setting)3 ArrayList (java.util.ArrayList)2 File (java.io.File)1 AccountController (org.jbei.ice.lib.account.AccountController)1 ConfigurationKey (org.jbei.ice.lib.dto.ConfigurationKey)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1 EntriesAsCSV (org.jbei.ice.lib.entry.EntriesAsCSV)1 RemoteEntriesAsCSV (org.jbei.ice.lib.net.RemoteEntriesAsCSV)1 Configuration (org.jbei.ice.storage.model.Configuration)1