Search in sources :

Example 1 with AccountController

use of org.jbei.ice.lib.account.AccountController in project ice by JBEI.

the class RemoteEntries method transferEntries.

/**
     * Schedules a task to handle the transfer
     *
     * @param userId    identifier of user making request
     * @param remoteId  local unique identifier for partner to transfer to
     * @param selection context for generating entries to transfer or list of entries
     * @throws PermissionException if user making request is not an administrator
     */
public void transferEntries(String userId, long remoteId, EntrySelection selection) {
    AccountController accountController = new AccountController();
    if (!accountController.isAdministrator(userId))
        throw new PermissionException("Administrative privileges required to transfer entries");
    TransferTask task = new TransferTask(userId, remoteId, selection);
    IceExecutorService.getInstance().runTask(task);
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) TransferTask(org.jbei.ice.lib.executor.TransferTask) AccountController(org.jbei.ice.lib.account.AccountController)

Example 2 with AccountController

use of org.jbei.ice.lib.account.AccountController in project ice by JBEI.

the class ModelToInfoFactory method getCommon.

public static PartData getCommon(PartData info, Entry entry) {
    info.setId(entry.getId());
    info.setRecordId(entry.getRecordId());
    info.setPartId(entry.getPartNumber());
    info.setName(entry.getName());
    String owner = entry.getOwner();
    if (owner.trim().isEmpty())
        owner = entry.getOwnerEmail();
    info.setOwner(owner);
    info.setOwnerEmail(entry.getOwnerEmail());
    Account ownerAccount = DAOFactory.getAccountDAO().getByEmail(info.getOwnerEmail());
    if (ownerAccount != null)
        info.setOwnerId(ownerAccount.getId());
    info.setCreator(entry.getCreator());
    info.setCreatorEmail(entry.getCreatorEmail());
    Account creatorAccount = DAOFactory.getAccountDAO().getByEmail(info.getCreatorEmail());
    if (creatorAccount != null)
        info.setCreatorId(creatorAccount.getId());
    AccountController accountController = new AccountController();
    try {
        long ownerId = accountController.getAccountId(entry.getOwnerEmail());
        info.setOwnerId(ownerId);
        if (entry.getCreatorEmail() != null && !entry.getCreatorEmail().isEmpty()) {
            long creatorId = accountController.getAccountId(entry.getCreatorEmail());
            info.setCreatorId(creatorId);
        }
    } catch (Exception ce) {
        Logger.debug(ce.getMessage());
    }
    info.setAlias(entry.getAlias());
    info.setKeywords(entry.getKeywords());
    info.setStatus(entry.getStatus());
    info.setShortDescription(entry.getShortDescription());
    info.setCreationTime(entry.getCreationTime().getTime());
    info.setModificationTime(entry.getModificationTime().getTime());
    info.setBioSafetyLevel(entry.getBioSafetyLevel());
    info.setLongDescription(entry.getLongDescription());
    info.setIntellectualProperty(entry.getIntellectualProperty());
    info.setSelectionMarkers(EntryUtil.getSelectionMarkersAsList(entry.getSelectionMarkers()));
    // funding sources
    info.setFundingSource(entry.getFundingSource());
    info.setPrincipalInvestigator(entry.getPrincipalInvestigator());
    try {
        if (!StringUtils.isEmpty(entry.getPrincipalInvestigatorEmail())) {
            Account piAccount = accountController.getByEmail(entry.getPrincipalInvestigatorEmail());
            if (piAccount != null) {
                info.setPrincipalInvestigator(piAccount.getFullName());
                info.setPrincipalInvestigatorEmail(piAccount.getEmail());
                info.setPrincipalInvestigatorId(piAccount.getId());
            } else
                info.setPrincipalInvestigatorEmail(entry.getPrincipalInvestigatorEmail());
        }
    } catch (Exception e) {
        Logger.debug(e.getMessage());
    }
    ArrayList<String> links = new ArrayList<>();
    if (entry.getLinks() != null) {
        for (Link link : entry.getLinks()) {
            links.add(link.getLink());
        }
    }
    info.setLinks(links);
    ArrayList<CustomField> params = new ArrayList<>();
    if (entry.getParameters() != null) {
        for (Parameter parameter : entry.getParameters()) {
            CustomField paramInfo = new CustomField();
            paramInfo.setId(parameter.getId());
            paramInfo.setName(parameter.getKey());
            paramInfo.setValue(parameter.getValue());
            params.add(paramInfo);
        }
    }
    info.setCustomFields(params);
    // get visibility
    info.setVisibility(Visibility.valueToEnum(entry.getVisibility()));
    info.setLongDescription(entry.getLongDescription());
    info.setShortDescription(entry.getShortDescription());
    info.setReferences(entry.getReferences());
    // linked entries
    for (Entry linkedEntry : entry.getLinkedEntries()) {
        PartData linkedPartData = getInfo(linkedEntry);
        if (linkedPartData != null)
            info.getLinkedParts().add(linkedPartData);
    }
    return info;
}
Also used : ArrayList(java.util.ArrayList) AccountController(org.jbei.ice.lib.account.AccountController)

Example 3 with AccountController

use of org.jbei.ice.lib.account.AccountController in project ice by JBEI.

the class Entries method updateVisibility.

public boolean updateVisibility(List<Long> entryIds, Visibility visibility) {
    Account account = accountDAO.getByEmail(userId);
    List<Group> accountGroups = new GroupController().getAllGroups(account);
    if (!new AccountController().isAdministrator(userId) && !permissionDAO.canWrite(account, accountGroups, entryIds))
        return false;
    for (long entryId : entryIds) {
        Entry entry = dao.get(entryId);
        if (entry.getVisibility() == visibility.getValue())
            continue;
        entry.setVisibility(visibility.getValue());
        dao.update(entry);
    }
    return true;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) AccountController(org.jbei.ice.lib.account.AccountController)

Example 4 with AccountController

use of org.jbei.ice.lib.account.AccountController in project ice by JBEI.

the class ConfigurationController method autoUpdateSetting.

// update the setting automatically. Currently works only for blast installations
public Setting autoUpdateSetting(String userId, Setting setting) {
    AccountController accountController = new AccountController();
    if (!accountController.isAdministrator(userId))
        throw new PermissionException("Cannot auto update system setting without admin privileges");
    Configuration configuration = dao.get(setting.getKey());
    if (configuration == null) {
        Logger.error("Could not retrieve setting " + setting.getKey());
        return null;
    }
    String osName = System.getProperty("os.name").replaceAll("\\s+", "").toLowerCase();
    String blast = "ncbi-blast-2.6.0+-x64-" + osName + ".tar.gz";
    Path path = Paths.get(dao.get(ConfigurationKey.TEMPORARY_DIRECTORY).getValue(), blast);
    Path dest = Paths.get(dao.get(ConfigurationKey.DATA_DIRECTORY).getValue());
    if (!Files.exists(dest)) {
        Logger.error("Cannot access access dir : " + dest.toString());
        return null;
    }
    try (InputStream is = (new URL(BLAST_FTP_DIR + blast)).openStream()) {
        Files.copy(is, path.toAbsolutePath(), StandardCopyOption.REPLACE_EXISTING);
        Archiver archiver = ArchiverFactory.createArchiver("tar", "gz");
        archiver.extract(path.toFile(), dest.toFile());
        Path valuePath = Paths.get(dest.toString(), "ncbi-blast-2.6.0+", "bin");
        configuration.setValue(valuePath.toString());
        Files.list(valuePath).forEach(dirPath -> {
            try {
                Files.setPosixFilePermissions(dirPath, PosixFilePermissions.fromString("rwxrwxrwx"));
            } catch (IOException e) {
                Logger.error(e);
            }
        });
        return dao.update(configuration).toDataTransferObject();
    } catch (Exception e) {
        Logger.error(e);
        return null;
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Path(java.nio.file.Path) Configuration(org.jbei.ice.storage.model.Configuration) InputStream(java.io.InputStream) IOException(java.io.IOException) Archiver(org.rauschig.jarchivelib.Archiver) URL(java.net.URL) IOException(java.io.IOException) PermissionException(org.jbei.ice.lib.access.PermissionException) AccountController(org.jbei.ice.lib.account.AccountController)

Example 5 with AccountController

use of org.jbei.ice.lib.account.AccountController 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)

Aggregations

AccountController (org.jbei.ice.lib.account.AccountController)15 Account (org.jbei.ice.storage.model.Account)5 PermissionException (org.jbei.ice.lib.access.PermissionException)3 GroupController (org.jbei.ice.lib.group.GroupController)3 Configuration (org.jbei.ice.storage.model.Configuration)3 ArrayList (java.util.ArrayList)2 ConfigurationKey (org.jbei.ice.lib.dto.ConfigurationKey)2 Group (org.jbei.ice.storage.model.Group)2 RemotePartner (org.jbei.ice.storage.model.RemotePartner)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)1 ConfigurationController (org.jbei.ice.lib.config.ConfigurationController)1 Setting (org.jbei.ice.lib.dto.Setting)1 Results (org.jbei.ice.lib.dto.common.Results)1 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1