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);
}
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;
}
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;
}
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;
}
}
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;
}
Aggregations