1. deech
  2. xdat_release

Commits

deech  committed ce7d5f4

Commited outstanding changes to the anonymization feature

  • Participants
  • Parent commits 0e85306
  • Branches default

Comments (0)

Files changed (3)

File plugin-resources/webapp/xnat/java/org/nrg/xdat/om/base/BaseXnatExperimentdata.java

View file
  *
  */
 @SuppressWarnings({"unchecked","rawtypes"})
-public class BaseXnatExperimentdata extends AutoXnatExperimentdata implements ArchivableItem {
+public class BaseXnatExperimentdata extends AutoXnatExperimentdata implements ArchivableItem, MoveableI {
 
 	public BaseXnatExperimentdata(ItemI item)
 	{
     public void moveToProject(XnatProjectdata newProject,String newLabel,XDATUser user) throws Exception{
     	if(!this.getProject().equals(newProject.getId()))
     	{
-    		//Does user have permissions?
-    		if(!user.canEdit(this)){
+    		
+    		if (!Mover.check(this, user)) {
     			throw new InvalidPermissionException(this.getXSIType());
     		}
-    		
-    		
     		String existingRootPath=this.getProjectData().getRootArchivePath();
     		
     		if(newLabel==null)newLabel = this.getLabel();
     		
     		
     		for(XnatAbstractresourceI abstRes:this.getResources_resource()){
-    			String uri= null;
-    			if(abstRes instanceof XnatResource){
-    				uri=((XnatResource)abstRes).getUri();
-    			}else{
-    				uri=((XnatResourceseries)abstRes).getPath();
-    			}
-    			
-    			if(FileUtils.IsAbsolutePath(uri)){
-    				int lastIndex=uri.lastIndexOf(File.separator + current_label + File.separator);
-    				if(lastIndex>-1)
-    				{  
-    					lastIndex+=1+current_label.length();
-    				}
-    				if(lastIndex==-1){
-    					lastIndex=uri.lastIndexOf(File.separator + this.getId() + File.separator);
-        				if(lastIndex>-1)
-        				{
-        					lastIndex+=1+this.getId().length();
-        				}
-    				}
-    				String existingSessionDir=null;
-    				if(lastIndex>-1){
-        				//in session_dir
-        				existingSessionDir=uri.substring(0,lastIndex);
-        			}else{
-        				//outside session_dir
-//        				newSessionDir = new File(newSessionDir,"RESOURCES");
-//        				newSessionDir = new File(newSessionDir,"RESOURCES/"+abstRes.getXnatAbstractresourceId());
-//        				int lastSlash=uri.lastIndexOf("/");
-//        				if(uri.lastIndexOf("\\")>lastSlash){
-//        					lastSlash=uri.lastIndexOf("\\");
-//        				}
-//        				existingSessionDir=uri.substring(0,lastSlash);
-        				//don't attempt to move sessions which are outside of the Session Directory.
-        				throw new Exception("Non-standard file location for file(s):" + uri);
-        			}
-        			((XnatAbstractresource)abstRes).moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
-    			}else{
-    				((XnatAbstractresource)abstRes).moveTo(newSessionDir,null,existingRootPath,user);
-    			}
+    			Mover.moveResource(abstRes, current_label, this, newSessionDir, existingRootPath, user);
     		}
     		
-    		XFTItem current=this.getCurrentDBVersion(false);
-    		current.setProperty("project", newProject.getId());
-    		current.setProperty("label", newLabel);    		
-    		current.save(user, true, false); 
-    		
-    		this.setProject(newProject.getId());
-    		this.setLabel(newLabel);
+    		Mover.writeDB(this, newProject, newLabel, user);
+    		Mover.setLocal(this, newProject, newLabel);
     	}
     }
     

File plugin-resources/webapp/xnat/java/org/nrg/xdat/om/base/BaseXnatImagesessiondata.java

View file
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import org.nrg.xdat.base.BaseElement;
 import org.nrg.xdat.bean.CatCatalogBean;
 import org.nrg.xft.utils.FileUtils;
 import org.nrg.xft.utils.StringUtils;
 import org.nrg.xnat.exceptions.InvalidArchiveStructure;
+import org.nrg.xnat.helpers.merge.CopyOp;
+import org.nrg.xnat.helpers.merge.RollbackException;
+import org.nrg.xnat.helpers.merge.Run;
+import org.nrg.xnat.helpers.merge.TransactionException;
 import org.nrg.xnat.srb.XNATDirectory;
 import org.nrg.xnat.srb.XNATMetaData;
 import org.nrg.xnat.srb.XNATSrbSearch;
     	return customfields;
     }
     
-    public void moveToProject(XnatProjectdata newProject,String newLabel,XDATUser user) throws Exception{
+    public void moveToProject(final XnatProjectdata newProject,String label , final XDATUser user) throws Exception{
     	if(!this.getProject().equals(newProject.getId()))
     	{
-    		if(!user.canEdit(this)){
+    		if (!Mover.check(this, user)) {
     			throw new InvalidPermissionException(this.getXSIType());
     		}
     		
-    		String existingRootPath=this.getProjectData().getRootArchivePath();
+    		final File rootBackup=Mover.createPrimaryBackupDirectory("move",this.getProject(),label);
+    		final String existingRootPath=this.getProjectData().getRootArchivePath();
+    		final String newLabel = label == null? (this.getLabel() == null ? this.getId() : this.getLabel()) : null;
+    		final File newSessionDir = new File(new File(newProject.getRootArchivePath(),newProject.getCurrentArc()),newLabel);
+    		final String current_label=this.getLabel() == null ? this.getId() : this.getLabel();
+    		final BaseXnatImagesessiondata base = this;
     		
-    		if(newLabel==null)newLabel = this.getLabel();
-    		if(newLabel==null)newLabel = this.getId();
+    		CopyOp<java.lang.Void> scanOp = new CopyOp<java.lang.Void>(new Callable<java.lang.Void>(){
+				public java.lang.Void call() throws Exception {
+					for(XnatImagescandataI scan: getScans_scan()){
+		    			for(XnatAbstractresourceI abstRes: scan.getFile()){
+		    				Mover.moveResource(abstRes, current_label, base, newSessionDir, existingRootPath, user);
+		    			}
+		    		}
+		    		
+		    		for(XnatReconstructedimagedataI recon:base.getReconstructions_reconstructedimage()){
+		    			for(XnatAbstractresourceI abstRes: recon.getOut_file()){
+		    				Mover.moveResource(abstRes, current_label, base, newSessionDir, existingRootPath, user);
+		    			}
+		    		}
+		    		
+		    		for(XnatImageassessordataI assessor:base.getAssessors_assessor()){
+		    			for(XnatAbstractresourceI abstRes: assessor.getOut_file()){
+		    				Mover.moveResource(abstRes, current_label, base, newSessionDir, existingRootPath, user);
+		    			}
+		    		}
+		    		BaseXnatImagesessiondata.super.moveToProject(newProject, newLabel, user);
+		    		return null;
+				}
+			}, this.getSessionDir(), rootBackup, "src_backup");
     		
-    		final File newSessionDir = new File(new File(newProject.getRootArchivePath(),newProject.getCurrentArc()),newLabel);
-    		
-    		String current_label=this.getLabel();
-    		if(current_label==null)current_label=this.getId();
-    		
-    		for(XnatImagescandataI scan:this.getScans_scan()){
-    			for(XnatAbstractresourceI abstRes: scan.getFile()){
-        			String uri= null;
-        			if(abstRes instanceof XnatResource){
-        				uri=((XnatResource)abstRes).getUri();
-        			}else{
-        				uri=((XnatResourceseries)abstRes).getPath();
-        			}
-        			
-        			if(FileUtils.IsAbsolutePath(uri)){
-        				int lastIndex=uri.lastIndexOf(File.separator + current_label + File.separator);
-        				if(lastIndex>-1)
-        				{
-        					lastIndex+=1+current_label.length();
-        				}
-        				if(lastIndex==-1){
-        					lastIndex=uri.lastIndexOf(File.separator + this.getId() + File.separator);
-            				if(lastIndex>-1)
-            				{
-            					lastIndex+=1+this.getId().length();
-            				}
-        				}
-        				String existingSessionDir=null;
-        				if(lastIndex>-1){
-            				//in session_dir
-            				existingSessionDir=uri.substring(0,lastIndex);
-            			}else{
-            				//outside session_dir
-//            				newSessionDir = new File(new File(newSessionDir,"SCANS"),scan.getId());
-//            				int lastSlash=uri.lastIndexOf("/");
-//            				if(uri.lastIndexOf("\\")>lastSlash){
-//            					lastSlash=uri.lastIndexOf("\\");
-//            				}
-//            				existingSessionDir=uri.substring(0,lastSlash);
-            				//don't attempt to move sessions which are outside of the Session Directory.
-            				throw new Exception("Non-standard file location for file(s):" + uri);
-            			}
-            			((XnatAbstractresource)abstRes).moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
-        			}else{
-        				((XnatAbstractresource)abstRes).moveTo(newSessionDir,null,existingRootPath,user);
-        			}
-    			}
+    		try {
+    			Run.runTransaction(scanOp);
     		}
-    		
-    		for(XnatReconstructedimagedataI recon:this.getReconstructions_reconstructedimage()){
-    			for(XnatAbstractresourceI abstRes: recon.getOut_file()){
-        			String uri= null;
-        			if(abstRes instanceof XnatResource){
-        				uri=((XnatResource)abstRes).getUri();
-        			}else{
-        				uri=((XnatResourceseries)abstRes).getPath();
-        			}
-        			
-        			if(FileUtils.IsAbsolutePath(uri)){
-        				int lastIndex=uri.lastIndexOf(File.separator + current_label + File.separator);
-        				if(lastIndex>-1)
-        				{
-        					lastIndex+=1+current_label.length();
-        				}
-        				if(lastIndex==-1){
-        					lastIndex=uri.lastIndexOf(File.separator + this.getId() + File.separator);
-            				if(lastIndex>-1)
-            				{
-            					lastIndex+=1+this.getId().length();
-            				}
-        				}
-        				String existingSessionDir=null;
-        				if(lastIndex>-1){
-            				//in session_dir
-            				existingSessionDir=uri.substring(0,lastIndex);
-            			}else{
-            				//outside session_dir
-//            				newSessionDir = new File(new File(newSessionDir,"PROCESSED"),recon.getId());
-//            				int lastSlash=uri.lastIndexOf("/");
-//            				if(uri.lastIndexOf("\\")>lastSlash){
-//            					lastSlash=uri.lastIndexOf("\\");
-//            				}
-//            				existingSessionDir=uri.substring(0,lastSlash);
-            				//don't attempt to move sessions which are outside of the Session Directory.
-            				throw new Exception("Non-standard file location for file(s):" + uri);
-            			}
-        				((XnatAbstractresource)abstRes).moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
-        			}else{
-        				((XnatAbstractresource)abstRes).moveTo(newSessionDir,null,existingRootPath,user);
-        			}
-    			}
+    		catch (TransactionException e) {
+    			throw new Exception(e);
     		}
-    		
-    		for(XnatImageassessordataI assessor:this.getAssessors_assessor()){
-    			for(XnatAbstractresourceI abstRes: assessor.getOut_file()){
-        			String uri= null;
-        			if(abstRes instanceof XnatResource){
-        				uri=((XnatResource)abstRes).getUri();
-        			}else{
-        				uri=((XnatResourceseries)abstRes).getPath();
-        			}
-        			
-        			if(FileUtils.IsAbsolutePath(uri)){
-        				int lastIndex=uri.lastIndexOf(File.separator + current_label + File.separator);
-        				if(lastIndex>-1)
-        				{
-        					lastIndex+=1+current_label.length();
-        				}
-        				if(lastIndex==-1){
-        					lastIndex=uri.lastIndexOf(File.separator + this.getId() + File.separator);
-            				if(lastIndex>-1)
-            				{
-            					lastIndex+=1+this.getId().length();
-            				}
-        				}
-        				String existingSessionDir=null;
-        				if(lastIndex>-1){
-            				//in session_dir
-            				existingSessionDir=uri.substring(0,lastIndex);
-            			}else{
-            				//outside session_dir
-//            				newSessionDir = new File(new File(newSessionDir,"ASSESSORS"),assessor.getId());
-//            				int lastSlash=uri.lastIndexOf("/");
-//            				if(uri.lastIndexOf("\\")>lastSlash){
-//            					lastSlash=uri.lastIndexOf("\\");
-//            				}
-//            				existingSessionDir=uri.substring(0,lastSlash);
-            				//don't attempt to move sessions which are outside of the Session Directory.
-            				throw new Exception("Non-standard file location for file(s):" + uri);
-            			}
-        				((XnatAbstractresource)abstRes).moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
-        			}else{
-        				((XnatAbstractresource)abstRes).moveTo(newSessionDir,null,existingRootPath,user);
-        			}
-    			}
+    		catch (RollbackException e) {
+    			throw new Exception(e);
     		}
-    		
-    		super.moveToProject(newProject, newLabel, user);
     	}
     }
     

File plugin-resources/webapp/xnat/java/org/nrg/xdat/om/base/BaseXnatSubjectdata.java

View file
  *
  */
 @SuppressWarnings({"unchecked","rawtypes"})
-public class BaseXnatSubjectdata extends AutoXnatSubjectdata implements ArchivableItem{
+public class BaseXnatSubjectdata extends AutoXnatSubjectdata implements ArchivableItem, MoveableI{
     protected ArrayList<ItemI> minLoadAssessors = null;
 
 	public BaseXnatSubjectdata(ItemI item)
     public void moveToProject(XnatProjectdata newProject,String newLabel,XDATUser user) throws Exception{
     	if(!this.getProject().equals(newProject.getId()))
     	{
-    		if(!user.canEdit(this)){
+    		if (!Mover.check(this, user)) {
     			throw new InvalidPermissionException(this.getXSIType());
     		}
     		
     		if(current_label==null)current_label=this.getId();
     		
     		for(XnatAbstractresourceI abstRes:this.getResources_resource()){
-    			String uri= null;
-    			if(abstRes instanceof XnatResource){
-    				uri=((XnatResource)abstRes).getUri();
-    			}else{
-    				uri=((XnatResourceseries)abstRes).getPath();
-    			}
-    			
-    			if(FileUtils.IsAbsolutePath(uri)){
-    				int lastIndex=uri.lastIndexOf(File.separator + current_label + File.separator);
-    				if(lastIndex>-1)
-    				{
-    					lastIndex+=1+current_label.length();
-    				}
-    				if(lastIndex==-1){
-    					lastIndex=uri.lastIndexOf(File.separator + this.getId() + File.separator);
-        				if(lastIndex>-1)
-        				{
-        					lastIndex+=1+this.getId().length();
-        				}
-    				}
-    				String existingSessionDir=null;
-    				if(lastIndex>-1){
-        				//in session_dir
-        				existingSessionDir=uri.substring(0,lastIndex);
-        			}else{
-        				//outside session_dir
-        				newSessionDir = new File(newSessionDir,"RESOURCES");
-        				newSessionDir = new File(newSessionDir,"RESOURCES/"+abstRes.getXnatAbstractresourceId());
-        				int lastSlash=uri.lastIndexOf("/");
-        				if(uri.lastIndexOf("\\")>lastSlash){
-        					lastSlash=uri.lastIndexOf("\\");
-        				}
-        				existingSessionDir=uri.substring(0,lastSlash);
-        			}
-        			((XnatAbstractresource)abstRes).moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
-    			}else{
-    				((XnatAbstractresource)abstRes).moveTo(newSessionDir,null,existingRootPath,user);
-    			}
+    			Mover.moveResource(abstRes, current_label, this, newSessionDir, existingRootPath, user);
     		}
     		
-    		XFTItem current=this.getCurrentDBVersion(false);
-    		current.setProperty("project", newProject.getId());
-    		current.setProperty("label", newLabel);    		
-    		current.save(user, true, false); 
-    		
-    		this.setProject(newProject.getId());
-    		this.setLabel(newLabel);
+    		Mover.writeDB(this, newProject, newLabel, user);
+    		Mover.setLocal(this, newProject, newLabel);
     	}
     }