use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class Entries method createEntry.
/**
* Create an entry in the database.
* <p/>
* Generates a new Part Number, the record id (UUID), version id, and timestamps.
* Optionally set the record globally visible or schedule an index rebuild.
*
* @param account account of user creating entry
* @param entry entry record being created
* @param accessPermissions list of permissions to associate with created entry
* @return entry that was saved in the database.
*/
private Entry createEntry(Account account, Entry entry, ArrayList<AccessPermission> accessPermissions) {
if (entry.getRecordId() == null) {
entry.setRecordId(Utils.generateUUID());
entry.setVersionId(entry.getRecordId());
}
entry.setCreationTime(Calendar.getInstance().getTime());
entry.setModificationTime(entry.getCreationTime());
if (StringUtils.isEmpty(entry.getOwner()))
entry.setOwner(account.getFullName());
if (StringUtils.isEmpty(entry.getOwnerEmail()))
entry.setOwnerEmail(account.getEmail());
if (entry.getSelectionMarkers() != null) {
for (SelectionMarker selectionMarker : entry.getSelectionMarkers()) {
selectionMarker.setEntry(entry);
}
}
if (entry.getLinks() != null) {
for (Link link : entry.getLinks()) {
link.setEntry(entry);
}
}
if (entry.getStatus() == null)
entry.setStatus("");
if (entry.getBioSafetyLevel() == null)
entry.setBioSafetyLevel(0);
entry = dao.create(entry);
EntryPermissions permissions = new EntryPermissions(entry.getRecordId(), userId);
// check for pi
String piEmail = entry.getPrincipalInvestigatorEmail();
if (StringUtils.isNotEmpty(piEmail)) {
permissions.addAccount(piEmail, true);
}
// add write permissions for owner
permissions.addAccount(account.getEmail(), true);
// add read permission for all public groups
ArrayList<Group> groups = new GroupController().getAllPublicGroupsForAccount(account);
for (Group group : groups) {
permissions.addGroup(group.getId(), false);
}
if (accessPermissions != null) {
for (AccessPermission accessPermission : accessPermissions) {
permissions.addAccount(accessPermission);
}
}
// rebuild blast database
if (sequenceDAO.hasSequence(entry.getId())) {
RebuildBlastIndexTask task = new RebuildBlastIndexTask(Action.CREATE, entry.getPartNumber());
IceExecutorService.getInstance().runTask(task);
}
return entry;
}
use of org.jbei.ice.lib.group.GroupController 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);
}
}
use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class HibernateSearch method checkEnableSecurityFilter.
/**
* Enables the security filter if the account does not have administrative privileges
*
* @param userId identifier for account which is checked for administrative privs
* @param fullTextQuery search fulltextquery for which filter is enabled
*/
private void checkEnableSecurityFilter(String userId, FullTextQuery fullTextQuery) {
Set<String> groupUUIDs = new HashSet<>();
Set<String> folderIds = new HashSet<>();
if (StringUtils.isEmpty(userId)) {
groupUUIDs.add(GroupController.PUBLIC_GROUP_UUID);
} else {
AccountController accountController = new AccountController();
if (accountController.isAdministrator(userId)) {
return;
}
groupUUIDs = new GroupController().retrieveAccountGroupUUIDs(userId);
folderIds = new Folders(userId).getCanReadFolderIds();
}
fullTextQuery.enableFullTextFilter("security").setParameter("account", userId).setParameter("folderIds", folderIds).setParameter("groupUUids", groupUUIDs);
}
use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class RemoteEntriesAsCSV method writeList.
private boolean writeList(List<RemotePartner> partners) throws IOException {
Path tmpPath = Paths.get(Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY));
File tmpFile = File.createTempFile("remote-ice-", ".csv", tmpPath.toFile());
csvPath = tmpFile.toPath();
FileWriter fileWriter = new FileWriter(tmpFile);
List<EntryFieldLabel> fields = getEntryFields();
String[] headers = getCSVHeaders(fields);
// csv file headers
File tmpZip = File.createTempFile("zip-", ".zip", tmpPath.toFile());
FileOutputStream fos = new FileOutputStream(tmpZip);
try (CSVWriter writer = new CSVWriter(fileWriter);
ZipOutputStream zos = new ZipOutputStream(fos)) {
writer.writeNext(headers);
// go through partners
for (RemotePartner partner : partners) {
try {
Logger.info("Retrieving from " + partner.getUrl());
PartnerEntries partnerEntries = remoteEntries.getPublicEntries(partner.getId(), 0, Integer.MAX_VALUE, null, true);
Results<PartData> webEntries = partnerEntries.getEntries();
if (webEntries == null || webEntries.getData() == null) {
Logger.error("Could not retrieve entries for " + partner.getUrl());
continue;
}
Logger.info("Obtained " + webEntries.getResultCount() + " from " + partner.getUrl());
// go through entries for each partner and write to the zip file
writeDataEntries(partner, webEntries.getData(), fields, writer, zos);
} catch (Exception e) {
Logger.warn("Exception retrieving entries " + e.getMessage());
}
}
// write local entries
if (this.includeLocal) {
Logger.info("Retrieving local public entries");
Group publicGroup = new GroupController().createOrRetrievePublicGroup();
Set<Group> groups = new HashSet<>();
groups.add(publicGroup);
EntryDAO entryDAO = DAOFactory.getEntryDAO();
List<Long> results = entryDAO.retrieveVisibleEntries(null, groups, ColumnField.CREATED, true, 0, Integer.MAX_VALUE, null);
writeLocalEntries(results, fields, writer, zos);
}
// write the csv file to the zip
writeZip(tmpZip, zos);
}
return true;
}
use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class FolderContents method addEntriesToFolders.
/**
* Attempts to add the specified list of entries to the specified folder destinations.
* The user making the request must have read privileges on the entries and write privileges on the destination
* folders.
* Any entries that the user is not permitted to read will not be be added and any destination folders that the user
* does not have write privileges for will not have entries added to it
*
* @param userId unique identifier for user making request
* @param entries list of entry identifiers to be added. Specified user must have read privileges on any
* that are to be added
* @param folders list of folders that that entries are to be added to
* @return list of destination folders that were updated successfully
*/
List<FolderDetails> addEntriesToFolders(String userId, List<Long> entries, List<FolderDetails> folders) {
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
List<Group> accountGroups = new GroupController().getAllGroups(account);
if (!folderAuthorization.isAdmin(userId))
entries = DAOFactory.getPermissionDAO().getCanReadEntries(account, accountGroups, entries);
if (entries == null || entries.isEmpty())
return new ArrayList<>();
for (FolderDetails details : folders) {
Folder folder = folderDAO.get(details.getId());
if (folder == null) {
Logger.warn("Could not add entries to folder " + details.getId() + " which doesn't exist");
continue;
}
if (!folderAuthorization.canWrite(userId, folder)) {
Logger.warn(userId + " lacks write privs on folder " + folder.getId());
continue;
}
// check if the folder is remote or local
if (folder.getType() == FolderType.REMOTE) {
Logger.info("Adding entries to remote folder " + folder.getId());
addToRemoteFolder(account, folder, entries);
} else {
List<Entry> entryModelList = DAOFactory.getEntryDAO().getEntriesByIdSet(entries);
folderDAO.addFolderContents(folder, entryModelList);
if (folder.isPropagatePermissions()) {
List<Permission> folderPermissions = permissionDAO.getFolderPermissions(folder);
addEntryPermission(userId, folderPermissions, entryModelList);
}
details.setCount(folderDAO.getFolderSize(folder.getId(), null, true));
}
}
return folders;
}
Aggregations