Skip to content

Commit

Permalink
Merge branch '4.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
hplahar committed Jun 17, 2015
2 parents 3a93b29 + b322e8d commit 0bd525e
Show file tree
Hide file tree
Showing 113 changed files with 18,282 additions and 21,885 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.jbei</groupId>
<artifactId>ice</artifactId>
<packaging>war</packaging>
<version>4.2.0</version>
<version>4.2.1</version>
<name>ice</name>
<description>Inventory of Composable Elements (ICE) for Synthetic Biology</description>
<repositories>
Expand Down Expand Up @@ -60,12 +60,12 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.9.Final</version>
<version>4.3.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>5.2.0.Final</version>
<artifactId>hibernate-search-orm</artifactId>
<version>5.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Expand All @@ -75,7 +75,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.8.Final</version>
<version>4.3.10.Final</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/org/jbei/ice/lib/bulkupload/BulkEntryCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jbei.ice.ApplicationController;
import org.jbei.ice.lib.access.Permission;
import org.jbei.ice.lib.account.AccountController;
import org.jbei.ice.lib.account.model.Account;
import org.jbei.ice.lib.common.logging.Logger;
Expand Down Expand Up @@ -125,6 +126,20 @@ protected PartData createEntryForUpload(String userId, PartData data, BulkUpload
}

entry = entryDAO.create(entry);

// check for pi
String piEmail = entry.getPrincipalInvestigatorEmail();
if (StringUtils.isNotEmpty(piEmail)) {
Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail);
if (pi != null) {
// add write permission for the PI
addWritePermission(pi, entry);
}
}

// add write permissions for owner
addWritePermission(account, entry);

upload.getContents().add(entry);

dao.update(upload);
Expand Down Expand Up @@ -385,6 +400,15 @@ public BulkUploadInfo createOrUpdateEntries(String userId, long draftId, List<Pa
return uploadInfo;
}

protected void addWritePermission(Account account, Entry entry) {
Permission permission = new Permission();
permission.setCanWrite(true);
permission.setEntry(entry);
entry.getPermissions().add(permission); // triggers the permission class bridge
permission.setAccount(account);
DAOFactory.getPermissionDAO().create(permission);
}

public boolean createEntries(String userId, long draftId, List<PartData> data, HashMap<String, InputStream> files) {
BulkUpload draft = dao.get(draftId);
if (draft == null)
Expand Down Expand Up @@ -420,6 +444,8 @@ public boolean createEntries(String userId, long draftId, List<PartData> data, H
linked.setId(linkedEntry.getId());
linked.setModificationTime(linkedEntry.getModificationTime().getTime());

addWritePermission(account, linkedEntry);

// check for attachments and sequences for linked entry
saveFiles(linked, linkedEntry, files);

Expand All @@ -429,6 +455,19 @@ public boolean createEntries(String userId, long draftId, List<PartData> data, H
}

entry = entryDAO.create(entry);
// check for pi
String piEmail = entry.getPrincipalInvestigatorEmail();
if (StringUtils.isNotEmpty(piEmail)) {
Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail);
if (pi != null) {
// add write permission for the PI
addWritePermission(pi, entry);
}
}

// add write permissions for owner
addWritePermission(account, entry);

draft.getContents().add(entry);

dao.update(draft);
Expand Down
44 changes: 29 additions & 15 deletions src/main/java/org/jbei/ice/lib/bulkupload/BulkUploadController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jbei.ice.lib.entry.attachment.AttachmentController;
import org.jbei.ice.lib.entry.model.Entry;
import org.jbei.ice.lib.entry.sequence.SequenceController;
import org.jbei.ice.lib.executor.IceExecutorService;
import org.jbei.ice.lib.group.Group;
import org.jbei.ice.lib.group.GroupController;
import org.jbei.ice.lib.models.Sequence;
Expand Down Expand Up @@ -77,9 +78,11 @@ public BulkUploadInfo create(String userId, BulkUploadInfo info) {
upload.setAccount(account);
upload.setCreationTime(new Date());
upload.setLastUpdateTime(upload.getCreationTime());
if (info.getStatus() == BulkUploadStatus.BULK_EDIT)
if (info.getStatus() == BulkUploadStatus.BULK_EDIT) {
// only one instance of bulk edit is allowed to remain
clearBulkEdits(userId);
upload.setStatus(BulkUploadStatus.BULK_EDIT);
else
} else
upload.setStatus(BulkUploadStatus.IN_PROGRESS);

upload.setImportType(info.getType());
Expand Down Expand Up @@ -113,6 +116,28 @@ public BulkUploadInfo create(String userId, BulkUploadInfo info) {
return upload.toDataTransferObject();
}

/**
* Removes any bulk edits belonging to the specified user
*
* @param userId unique identifier for user whose bulk edits are to be removed
*/
protected void clearBulkEdits(String userId) {
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
if (account == null)
return;

List<BulkUpload> userEdits = dao.retrieveByAccount(account);
if (userEdits == null || userEdits.isEmpty())
return;

for (BulkUpload upload : userEdits) {
if (upload.getStatus() != BulkUploadStatus.BULK_EDIT)
continue;
upload.getContents().clear();
dao.delete(upload);
}
}

/**
* Retrieves list of bulk imports that are owned by the system. System ownership is assigned to
* all bulk imports that are submitted by non-admins and indicates that it is pending approval.
Expand Down Expand Up @@ -283,19 +308,8 @@ public BulkUploadInfo deleteDraftById(String userId, long draftId) throws Permis
if (!userId.equals(draftAccount.getEmail()) && !accountController.isAdministrator(userId))
throw new PermissionException("No permissions to delete draft " + draftId);

// delete all associated entries. for strain with plasmids both are returned
// todo : use task to speed up process and also check for status

ArrayList<Long> entryIds = dao.getEntryIds(draft);
for (long entryId : entryIds) {
try {
entryController.delete(userId, entryId);
} catch (PermissionException pe) {
Logger.warn(userId + " does not have permission to delete" + entryId + " for bulk upload " + draftId);
}
}

dao.delete(draft);
BulkUploadDeleteTask task = new BulkUploadDeleteTask(userId, draftId);
IceExecutorService.getInstance().runTask(task);

BulkUploadInfo draftInfo = draft.toDataTransferObject();
AccountTransfer accountTransfer = draft.getAccount().toDataTransferObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.jbei.ice.lib.bulkupload;

import org.jbei.ice.lib.common.logging.Logger;
import org.jbei.ice.lib.dao.DAOFactory;
import org.jbei.ice.lib.dao.hibernate.BulkUploadDAO;
import org.jbei.ice.lib.dto.entry.Visibility;
import org.jbei.ice.lib.entry.model.Entry;
import org.jbei.ice.lib.executor.Task;


/**
* Task to delete bulk uploads with a status of draft and their contents.
*
* @author Hector Plahar
*/
public class BulkUploadDeleteTask extends Task {

private final long bulkUploadId;
private final String userId;

public BulkUploadDeleteTask(final String userId, final long id) {
this.bulkUploadId = id;
this.userId = userId;
}

@Override
public void execute() {
BulkUploadDAO dao = DAOFactory.getBulkUploadDAO();

BulkUpload upload = dao.get(bulkUploadId);
if (upload == null) {
Logger.error("Could not locate bulk upload " + bulkUploadId + " for deletion");
return;
}

BulkUploadAuthorization authorization = new BulkUploadAuthorization();
authorization.expectWrite(userId, upload);

if (upload.getStatus() != BulkUploadStatus.IN_PROGRESS)
return;

// delete all associated entries that have a status of draft
for (Entry entry : upload.getContents()) {
for (Entry linkedEntry : entry.getLinkedEntries()) {
if (linkedEntry.getVisibility() != Visibility.DRAFT.getValue())
continue;

DAOFactory.getEntryDAO().fullDelete(linkedEntry);
// entryController.fullDelete(userId, linkedEntry.getId());
}

if (entry.getVisibility() == Visibility.DRAFT.getValue()) {
DAOFactory.getEntryDAO().fullDelete(entry);
// entryController.fullDelete(userId, entry.getId());
}
}

dao.delete(upload);
}
}
Loading

0 comments on commit 0bd525e

Please sign in to comment.