ORCentral
|
00001 package eu.coform.command.datasetingestion; 00002 00003 import eu.coform.Dataset; 00004 import eu.coform.Error; 00005 import eu.coform.Filestruct; 00006 import eu.coform.Group; 00007 import eu.coform.ORException; 00008 import eu.coform.Session; 00009 import eu.coform.command.CreateNewUUIDCommand; 00010 import eu.coform.command.loginsession.IsValidSessionCommand; 00011 import eu.coform.command.proto.Abstract; 00012 import eu.coform.database.DBException; 00013 import eu.coform.database.command.InsertDatasetDBCommand; 00014 import eu.coform.database.command.InsertFileDBCommand; 00015 import eu.coform.database.command.IntIDDBCommand; 00016 import eu.coform.database.command.UserIdForSessDBCommand; 00017 00021 public class IngestDatasetCommand implements AbstractSectionDatasetIngestion { 00022 00023 private Session session; 00024 // private Group parentGroup; TODO: ignored for now 00025 private Dataset dataset; 00026 private String metadataRDF; 00027 00034 public IngestDatasetCommand(Session session, Dataset dataset,String metadataRDF){ 00035 this.session = session; 00036 this.dataset = dataset; 00037 this.metadataRDF = metadataRDF; 00038 } 00039 00050 @Override 00051 public Object execute() throws ORException { 00052 //TODO testing, will be done later 00053 IsValidSessionCommand sessionCom = new IsValidSessionCommand(); 00054 sessionCom.setSession(session); 00055 Boolean valid = sessionCom.execute(); 00056 00057 if(valid.booleanValue() == false) 00058 throw new ORException(Error.SessionInvalid); 00059 00060 Filestruct areatab = dataset.getFileAreatable(); 00061 Filestruct binaryfile = dataset.getFileBinary(); 00062 Filestruct filemetadata = dataset.getFileMetadata(); 00063 Filestruct thumb = dataset.getFileThumbnail(); 00064 00065 // UniqueIDs have to be set to null at the client site, these have to be x 00066 // created here 00067 if(areatab.getFilestructID() != null || binaryfile.getFilestructID()!= null || 00068 filemetadata.getFilestructID()!= null||thumb.getFilestructID()!= null|| 00069 dataset.getDatasetID()!= null){ 00070 throw new ORException(Error.DatasetInconistent); 00071 } 00072 00073 // TODO don't know, if it should be done here, but check if status is 00074 // set to incomplete 00075 00076 CreateNewUUIDCommand idCom = new CreateNewUUIDCommand(); 00077 00078 dataset.setDatasetID(idCom.execute()); 00079 areatab.setFilestructID(idCom.execute()); 00080 binaryfile.setFilestructID(idCom.execute()); 00081 filemetadata.setFilestructID(idCom.execute()); 00082 thumb.setFilestructID(idCom.execute()); 00083 00084 areatab.setDatasetID(dataset.getDatasetID()); 00085 binaryfile.setDatasetID(dataset.getDatasetID()); 00086 filemetadata.setDatasetID(dataset.getDatasetID()); 00087 thumb.setDatasetID(dataset.getDatasetID()); 00088 00089 00090 UserIdForSessDBCommand userIdCom = new UserIdForSessDBCommand(session); 00091 try { 00092 userIdCom.exec(); 00093 } catch (DBException e) { 00094 throw new ORException(Error.SessionInvalid); 00095 } 00096 int userId = userIdCom.getResult(); 00097 00098 InsertFileDBCommand insertAreaCom = new InsertFileDBCommand(areatab, userId); 00099 InsertFileDBCommand insertBinaryCom = new InsertFileDBCommand(binaryfile, userId); 00100 InsertFileDBCommand insertMetaCom = new InsertFileDBCommand(filemetadata, userId); 00101 InsertFileDBCommand insertThumbCom = new InsertFileDBCommand(thumb, userId); 00102 00103 try { 00104 insertAreaCom.exec(); 00105 insertBinaryCom.exec(); 00106 insertMetaCom.exec(); 00107 insertThumbCom.exec(); 00108 } catch (DBException e) { 00109 throw new ORException(Error.FilestructIdInvalid); 00110 } 00111 00112 IntIDDBCommand datasetIdIntCom = new IntIDDBCommand(dataset.getDatasetID()); 00113 IntIDDBCommand areaIdIntCom = new IntIDDBCommand(areatab.getFilestructID()); 00114 IntIDDBCommand metaIdIntCom = new IntIDDBCommand(filemetadata.getFilestructID()); 00115 IntIDDBCommand binaryIdIntCom = new IntIDDBCommand(binaryfile.getFilestructID()); 00116 IntIDDBCommand thumbIdIntCom = new IntIDDBCommand(thumb.getFilestructID()); 00117 00118 try { 00119 datasetIdIntCom.exec(); 00120 areaIdIntCom.exec(); 00121 metaIdIntCom.exec(); 00122 binaryIdIntCom.exec(); 00123 thumbIdIntCom.exec(); 00124 } catch (DBException e) { 00125 throw new ORException(Error.FilestructIdInvalid); 00126 } 00127 00128 InsertDatasetDBCommand insertdDatCom = 00129 new InsertDatasetDBCommand(datasetIdIntCom.getResult(), 00130 areaIdIntCom.getResult(), 00131 metaIdIntCom.getResult(), 00132 binaryIdIntCom.getResult(), 00133 thumbIdIntCom.getResult()); 00134 00135 try { 00136 insertdDatCom.exec(); 00137 } catch (DBException e) { 00138 throw new ORException(Error.DatasetInconistent); 00139 } 00140 00141 return null; 00142 } 00143 00144 }