Skip to content

Commit

Permalink
check status of upload before assigning draft status to entry (SYNBIO…
Browse files Browse the repository at this point in the history
…-917)
  • Loading branch information
hplahar committed Jan 9, 2015
1 parent 4560b5c commit cc10501
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
25 changes: 13 additions & 12 deletions src/main/java/org/jbei/ice/lib/bulkupload/BulkEntryCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public BulkEntryCreator() {
}

protected BulkUpload createOrRetrieveBulkUpload(Account account, BulkUploadAutoUpdate autoUpdate,
EntryType addType) {
EntryType addType) {
BulkUpload draft = dao.get(autoUpdate.getBulkUploadId());
if (draft == null) {
draft = new BulkUpload();
Expand Down Expand Up @@ -132,8 +132,9 @@ public PartData updateEntry(String userId, long bulkUploadId, long id, PartData
BulkUpload upload = dao.get(bulkUploadId);
authorization.expectWrite(userId, upload);

// todo : check that entry is a part of upload and they are of the same type
Entry entry = entryDAO.get(id);
if (upload.getStatus() != BulkUploadStatus.BULK_EDIT)
entry.setVisibility(Visibility.DRAFT.getValue());
data = doUpdate(userId, entry, data);
if (data == null)
return null;
Expand All @@ -148,8 +149,7 @@ protected PartData doUpdate(String userId, Entry entry, PartData data) {
return null;

entry = InfoToModelFactory.updateEntryField(data, entry);
entry.setVisibility(Visibility.DRAFT.getValue());
entry.setModificationTime(new Date(System.currentTimeMillis()));
entry.setModificationTime(new Date());
entry = entryDAO.update(entry);

data.setModificationTime(entry.getModificationTime().getTime());
Expand Down Expand Up @@ -217,7 +217,7 @@ public BulkUploadInfo updateStatus(String userId, long id, BulkUploadStatus stat
// approved by an administrator
case APPROVED:
Account account = accountController.getByEmail(userId);
if (new BulkUploadController().approveBulkImport(account, id))
if (new BulkUploadController().approveBulkImport(userId, id))
return upload.toDataTransferObject();
return null;

Expand All @@ -236,9 +236,8 @@ public BulkUploadInfo updateStatus(String userId, long id, BulkUploadStatus stat
* @param id unique identifier referencing the bulk upload
* @param name name to assign to the bulk upload
* @return data transfer object for the bulk upload.
* returns null if no
* @throws org.jbei.ice.lib.access.AuthorizationException
* is user performing action doesn't have privileges
* returns null if no
* @throws org.jbei.ice.lib.access.AuthorizationException is user performing action doesn't have privileges
*/
public BulkUploadInfo renameBulkUpload(String userId, long id, String name) {
BulkUpload upload = dao.get(id);
Expand All @@ -262,10 +261,10 @@ public BulkUploadInfo renameBulkUpload(String userId, long id, String name) {
* @param autoUpdate wrapper for information used to create entry
* @param addType type of entry being created
* @return updated wrapper for information used to create entry. Will contain additional information
* such as the unique identifier for the part, if one was created
* such as the unique identifier for the part, if one was created
*/
public BulkUploadAutoUpdate createOrUpdateEntry(String userId, BulkUploadAutoUpdate autoUpdate,
EntryType addType) {
EntryType addType) {
Account account = accountController.getByEmail(userId);
BulkUpload draft = null;

Expand Down Expand Up @@ -355,9 +354,11 @@ public BulkUploadInfo createOrUpdateEntries(String userId, long draftId, List<Pa
int index = datum.getIndex();

Entry entry = entryDAO.get(datum.getId());
if (entry != null)
if (entry != null) {
if (draft.getStatus() != BulkUploadStatus.BULK_EDIT)
entry.setVisibility(Visibility.DRAFT.getValue());
datum = doUpdate(userId, entry, datum);
else
} else
datum = createEntryForUpload(userId, datum, draft);

if (datum == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,9 @@ public HashMap<String, ArrayList<BulkUploadInfo>> getPendingImports(String userI
* @param userId identifier for account of user requesting
* @param id unique identifier for bulk import
* @return data transfer object with the retrieved bulk import data and associated entries
* @throws ControllerException
* @throws PermissionException
*/
public BulkUploadInfo retrieveById(String userId, long id, int start, int limit)
throws PermissionException {
public BulkUploadInfo retrieveById(String userId, long id, int start, int limit) throws PermissionException {
BulkUpload draft = dao.get(id);
if (draft == null)
return null;
Expand Down Expand Up @@ -413,9 +411,9 @@ public boolean revertSubmitted(Account account, long uploadId) throws Controller
return true;
}

public boolean approveBulkImport(Account account, long id) {
public boolean approveBulkImport(String userId, long id) {
// only admins allowed
if (!accountController.isAdministrator(account.getEmail())) {
if (!accountController.isAdministrator(userId)) {
Logger.warn("Only administrators can approve bulk imports");
return false;
}
Expand Down Expand Up @@ -455,16 +453,16 @@ public boolean approveBulkImport(Account account, long id) {
for (AccessPermission accessPermission : permissions) {
accessPermission.setTypeId(entry.getId());

permissionsController.addPermission(account.getEmail(), accessPermission);
permissionsController.addPermission(userId, accessPermission);
if (plasmid != null) {
accessPermission.setTypeId(plasmid.getId());
permissionsController.addPermission(account.getEmail(), accessPermission);
permissionsController.addPermission(userId, accessPermission);
}
}

entryController.update(account.getEmail(), entry);
entryController.update(userId, entry);
if (plasmid != null)
entryController.update(account.getEmail(), plasmid);
entryController.update(userId, plasmid);
}

// when done approving, delete the bulk upload record but not the entries associated with it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void testApproveBulkImport() throws Exception {

// submit draft
Assert.assertNotNull(controller.submitBulkImportDraft(account.getEmail(), autoUpdate.getBulkUploadId()));
Assert.assertTrue(controller.approveBulkImport(account, autoUpdate.getBulkUploadId()));
Assert.assertTrue(controller.approveBulkImport(account.getEmail(), autoUpdate.getBulkUploadId()));

// bulk upload should be deleted
BulkUploadInfo info = controller.retrieveById(account.getEmail(), autoUpdate.getBulkUploadId(), 0, 0);
Expand Down

0 comments on commit cc10501

Please sign in to comment.