You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2016/01/12 16:47:47 UTC
[04/24] airavata git commit: renaming the module
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/FileTransferServiceImpl.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/FileTransferServiceImpl.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/FileTransferServiceImpl.java
deleted file mode 100644
index b5ab8fb..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/FileTransferServiceImpl.java
+++ /dev/null
@@ -1,484 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential;
-import org.apache.airavata.file.manager.core.db.dao.FileTransferRequestDao;
-import org.apache.airavata.file.manager.core.remote.client.RemoteStorageClient;
-import org.apache.airavata.file.manager.core.remote.client.http.HTTPStorageClient;
-import org.apache.airavata.file.manager.core.remote.client.scp.SCPStorageClient;
-import org.apache.airavata.file.manager.core.remote.client.sftp.SFTPStorageClient;
-import org.apache.airavata.file.manager.cpi.FileManagerException;
-import org.apache.airavata.file.manager.cpi.FileTransferService;
-import org.apache.airavata.model.file.transfer.*;
-import org.apache.commons.io.IOUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.List;
-import java.util.UUID;
-
-public class FileTransferServiceImpl implements FileTransferService {
-
- private final static Logger logger = LoggerFactory.getLogger(FileTransferServiceImpl.class);
-
- private FileTransferRequestDao fileTransferRequestDao;
-
- public FileTransferServiceImpl() throws IOException {
- this.fileTransferRequestDao = new FileTransferRequestDao();
- }
-
- /**
- * Method to upload the give bytes to the destination storage system
- *
- * @param gatewayId
- * @param username
- * @param fileData
- * @param destHostName
- * @param destLoginName
- * @param destPort
- * @param destProtocol
- * @param destinationPath
- * @param destHostCredToken
- * @return
- * @throws FileManagerException
- */
- @Override
- public String uploadFile(String gatewayId, String username, byte[] fileData, String destHostName, String destLoginName, int destPort,
- StorageResourceProtocol destProtocol,
- String destinationPath, String destHostCredToken) throws FileManagerException {
- long transferTime = System.currentTimeMillis();
- if(destProtocol == StorageResourceProtocol.SCP || destProtocol == StorageResourceProtocol.SFTP) {
- Object credential = getCredential(destHostCredToken);
- SSHCredential sshCredential;
- if (credential instanceof SSHCredential) {
- sshCredential = (SSHCredential) credential;
- File srcFile = null;
- FileWriter fileWriter = null;
- FileTransferRequestModel fileTransferRequestModel = null;
- try {
- String srcFilePath = System.getProperty("java.io.tmpdir")+File.separator+ UUID.randomUUID().toString();
- srcFile = new File(srcFilePath);
- fileWriter = new FileWriter(srcFile);
- fileWriter.write(new String(fileData));
- fileWriter.close();
- RemoteStorageClient remoteStorageClient;
- if(destProtocol == StorageResourceProtocol.SCP)
- remoteStorageClient = new SCPStorageClient(destHostName, destPort, destLoginName,
- sshCredential.getPrivateKey(),
- sshCredential.getPublicKey(), sshCredential.getPassphrase().getBytes());
- else
- remoteStorageClient = new SFTPStorageClient(destHostName, destPort, destLoginName,
- sshCredential.getPrivateKey(),
- sshCredential.getPublicKey(), sshCredential.getPassphrase().getBytes());
-
- fileTransferRequestModel = new FileTransferRequestModel();
- fileTransferRequestModel.setGatewayId(gatewayId);
- fileTransferRequestModel.setUsername(username);
- fileTransferRequestModel.setSrcHostname(InetAddress.getLocalHost().getHostName());
- fileTransferRequestModel.setSrcProtocol(StorageResourceProtocol.LOCAL);
- fileTransferRequestModel.setDestHostname(destHostName);
- fileTransferRequestModel.setDestLoginName(destLoginName);
- fileTransferRequestModel.setDestPort(destPort);
- fileTransferRequestModel.setDestProtocol(destProtocol);
- fileTransferRequestModel.setDestFilePath(destinationPath);
- fileTransferRequestModel.setDestHostCredToken(destHostCredToken);
- fileTransferRequestModel.setFileTransferMode(FileTransferMode.SYNC);
- remoteStorageClient.writeFile(srcFile, destinationPath);
- transferTime = System.currentTimeMillis() - transferTime;
- fileTransferRequestModel.setTransferTime(transferTime);
- fileTransferRequestModel.setTransferStatus(FileTransferStatus.COMPLETED);
- fileTransferRequestModel.setCreatedTime(System.currentTimeMillis());
- fileTransferRequestModel.setLastModifiedType(fileTransferRequestModel.getCreatedTime());
- fileTransferRequestModel.setFileSize(srcFile.length());
- String transferId = fileTransferRequestDao.createFileTransferRequest(fileTransferRequestModel);
- return transferId;
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- if(fileTransferRequestModel != null) {
- fileTransferRequestModel.setTransferStatus(FileTransferStatus.FAILED);
- try {
- fileTransferRequestDao.createFileTransferRequest(fileTransferRequestModel);
- } catch (JsonProcessingException e1) {
- logger.error(e.getMessage(), e);
- throw new FileManagerException(e);
- }
- }
- throw new FileManagerException(e.getMessage());
- } finally {
- if(srcFile != null)
- srcFile.delete();
- if(fileWriter != null)
- try {
- fileWriter.close();
- } catch (IOException e) {
- logger.error(e.getMessage(), e);
- throw new FileManagerException(e);
- }
- }
- } else {
- throw new FileManagerException("Only SSHCredential type is supported");
- }
- }else{
- throw new FileManagerException(destProtocol.toString() + " protocol is not supported for this method");
- }
- }
-
- /**
- * Transfer file between two storage resources synchronously. Returns the file transfer request id
- *
- * @param gatewayId
- * @param username
- * @param srcHostname
- * @param srcLoginName
- * @param srcPort
- * @param srcProtocol
- * @param srcPath
- * @param srcHostCredToken
- * @param destHostname
- * @param destLoginName
- * @param destPort
- * @param destProtocol
- * @param destinationPath
- * @param destHostCredToken
- * @return
- * @throws FileManagerException
- */
- @Override
- public String transferFile(String gatewayId, String username, String srcHostname, String srcLoginName, int srcPort, StorageResourceProtocol srcProtocol,
- String srcPath, String srcHostCredToken, String destHostname, String destLoginName, int destPort,
- StorageResourceProtocol destProtocol, String destinationPath, String destHostCredToken)
- throws FileManagerException {
- long transferTime = System.currentTimeMillis();
- File srcFile = null;
- FileTransferRequestModel fileTransferRequestModel = null;
- try{
- fileTransferRequestModel = new FileTransferRequestModel();
- fileTransferRequestModel.setGatewayId(gatewayId);
- fileTransferRequestModel.setUsername(username);
- fileTransferRequestModel.setSrcHostname(srcHostname);
- fileTransferRequestModel.setSrcPort(srcPort);
- fileTransferRequestModel.setSrcLoginName(srcLoginName);
- fileTransferRequestModel.setSrcFilePath(srcPath);
- fileTransferRequestModel.setSrcProtocol(srcProtocol);
- fileTransferRequestModel.setSrcHostCredToken(srcHostCredToken);
- fileTransferRequestModel.setDestHostname(destHostname);
- fileTransferRequestModel.setDestPort(destPort);
- fileTransferRequestModel.setDestLoginName(destLoginName);
- fileTransferRequestModel.setDestFilePath(destinationPath);
- fileTransferRequestModel.setDestProtocol(destProtocol);
- fileTransferRequestModel.setDestHostCredToken(destHostCredToken);
- fileTransferRequestModel.setCreatedTime(System.currentTimeMillis());
- fileTransferRequestModel.setLastModifiedType(fileTransferRequestModel.getCreatedTime());
- fileTransferRequestModel.setFileTransferMode(FileTransferMode.SYNC);
-
- if(srcProtocol == StorageResourceProtocol.HTTP || srcProtocol == StorageResourceProtocol.HTTPS ||
- srcProtocol == StorageResourceProtocol.SCP || srcProtocol == StorageResourceProtocol.SFTP){
- RemoteStorageClient srcClient = null;
- if(srcProtocol == StorageResourceProtocol.HTTP){
- srcClient = new HTTPStorageClient(HTTPStorageClient.Protocol.HTTP, srcHostname, srcPort);
- }else if(srcProtocol == StorageResourceProtocol.HTTPS){
- srcClient = new HTTPStorageClient(HTTPStorageClient.Protocol.HTTPS, srcHostname, srcPort);
- }else if(srcProtocol == StorageResourceProtocol.SCP){
- Object credential = getCredential(srcHostCredToken);
- if(credential instanceof SSHCredential){
- SSHCredential sshCredential = (SSHCredential) credential;
- srcClient = new SCPStorageClient(srcHostname, srcPort, srcLoginName, sshCredential.getPrivateKey(),
- sshCredential.getPublicKey(), sshCredential.getPassphrase().getBytes());
- }else{
- throw new FileManagerException("Only support SSHCredentials for SCP host");
- }
- }else{
- Object credential = getCredential(srcHostCredToken);
- if(credential instanceof SSHCredential){
- SSHCredential sshCredential = (SSHCredential) credential;
- srcClient = new SFTPStorageClient(srcHostname, srcPort, srcLoginName, sshCredential.getPrivateKey(),
- sshCredential.getPublicKey(), sshCredential.getPassphrase().getBytes());
- }else{
- throw new FileManagerException("Only support SSHCredentials for SFTP host");
- }
- }
- fileTransferRequestModel.setTransferStatus(FileTransferStatus.RUNNING);
- srcFile = srcClient.readFile(srcPath);
- }else{
- throw new FileManagerException("Unsupported src protocol " + srcProtocol);
- }
-
- if(destProtocol == StorageResourceProtocol.SCP || destProtocol == StorageResourceProtocol.SFTP){
- RemoteStorageClient destClient = null;
- if(destProtocol == StorageResourceProtocol.SCP){
- Object credential = getCredential(srcHostCredToken);
- if(credential instanceof SSHCredential){
- SSHCredential sshCredential = (SSHCredential) credential;
- destClient = new SCPStorageClient(srcHostname, srcPort, srcLoginName, sshCredential.getPrivateKey(),
- sshCredential.getPublicKey(), sshCredential.getPassphrase().getBytes());
- }else{
- throw new FileManagerException("Only support SSHCredentials for SCP host");
- }
- }else{
- Object credential = getCredential(srcHostCredToken);
- if(credential instanceof SSHCredential){
- SSHCredential sshCredential = (SSHCredential) credential;
- destClient = new SFTPStorageClient(srcHostname, srcPort, srcLoginName, sshCredential.getPrivateKey(),
- sshCredential.getPublicKey(), sshCredential.getPassphrase().getBytes());
- }else{
- throw new FileManagerException("Only support SSHCredentials for SFTP host");
- }
- }
- destClient.writeFile(srcFile, destinationPath);
- transferTime = System.currentTimeMillis() - transferTime;
- fileTransferRequestModel.setTransferTime(transferTime);
- fileTransferRequestModel.setFileSize(srcFile.length());
- fileTransferRequestModel.setTransferStatus(FileTransferStatus.COMPLETED);
- String transferId = fileTransferRequestDao.createFileTransferRequest(fileTransferRequestModel);
- return transferId;
- }else{
- throw new FileManagerException("Unsupported src protocol " + srcProtocol);
- }
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- if(fileTransferRequestModel != null) {
- fileTransferRequestModel.setTransferStatus(FileTransferStatus.FAILED);
- try {
- fileTransferRequestDao.createFileTransferRequest(fileTransferRequestModel);
- } catch (JsonProcessingException ex) {
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
- throw new FileManagerException(e);
- }finally {
- if(srcFile != null)
- srcFile.delete();
- }
- }
-
- /**
- * Transfer file between two storage resources asynchronously. Returns the file transfer request id
- *
- * @param gatewayId
- * @param username
- * @param srcHostname
- * @param srcLoginName
- * @param srcPort
- * @param srcProtocol
- * @param srcPath
- * @param srcHostCredToken
- * @param destHostname
- * @param destLoginName
- * @param destPort
- * @param destProtocol
- * @param destinationPath
- * @param destHostCredToken
- * @param callbackEmails
- * @return
- * @throws FileManagerException
- */
- @Override
- public String transferFileAsync(String gatewayId, String username, String srcHostname, String srcLoginName, int srcPort, StorageResourceProtocol srcProtocol,
- String srcPath, String srcHostCredToken, String destHostname, String destLoginName,
- int destPort, StorageResourceProtocol destProtocol, String destinationPath,
- String destHostCredToken, String[] callbackEmails) throws FileManagerException {
- return null;
- }
-
- /**
- * Get a directory listing of the specified source directory
- *
- * @param hostname
- * @param loginName
- * @param port
- * @param protocol
- * @param path
- * @param hostCredential
- * @return
- * @throws FileManagerException
- */
- @Override
- public List<LSEntryModel> getDirectoryListing(String hostname, String loginName, int port, StorageResourceProtocol protocol,
- String path, String hostCredential) throws FileManagerException {
- return null;
- }
-
- /**
- * Move file from one place to another inside the same storage resource
- *
- * @param hostname
- * @param loginName
- * @param port
- * @param protocol
- * @param hostCredential
- * @param sourcePath
- * @param destinationPath
- * @throws FileManagerException
- */
- @Override
- public void moveFile(String hostname, String loginName, int port, StorageResourceProtocol protocol, String hostCredential,
- String sourcePath, String destinationPath) throws FileManagerException {
-
- }
-
- /**
- * Rename a file
- *
- * @param hostname
- * @param loginName
- * @param port
- * @param protocol
- * @param hostCredential
- * @param sourcePath
- * @param newName
- * @throws FileManagerException
- */
- @Override
- public void renameFile(String hostname, String loginName, int port, StorageResourceProtocol protocol, String hostCredential,
- String sourcePath, String newName) throws FileManagerException {
-
- }
-
- /**
- * Create new directory
- *
- * @param hostname
- * @param loginName
- * @param port
- * @param protocol
- * @param hostCredential
- * @param dirPath
- * @throws FileManagerException
- */
- @Override
- public void mkdir(String hostname, String loginName, int port, StorageResourceProtocol protocol, String hostCredential,
- String dirPath) throws FileManagerException {
-
- }
-
- /**
- * Delete File in storage resource
- *
- * @param hostname
- * @param loginName
- * @param port
- * @param protocol
- * @param hostCredential
- * @param filePath
- * @throws FileManagerException
- */
- @Override
- public void deleteFile(String hostname, String loginName, int port, StorageResourceProtocol protocol, String hostCredential,
- String filePath) throws FileManagerException {
-
- }
-
- /**
- * Check whether the specified file exists
- *
- * @param hostname
- * @param loginName
- * @param port
- * @param protocol
- * @param hostCredential
- * @param filePath
- * @return
- * @throws FileManagerException
- */
- @Override
- public boolean isExists(String hostname, String loginName, int port, StorageResourceProtocol protocol, String hostCredential,
- String filePath) throws FileManagerException {
- return false;
- }
-
- /**
- * Check whether the path points to a directory
- *
- * @param hostname
- * @param loginName
- * @param port
- * @param protocol
- * @param hostCredential
- * @param filePath
- * @return
- * @throws FileManagerException
- */
- @Override
- public boolean isDirectory(String hostname, String loginName, int port, StorageResourceProtocol protocol, String hostCredential,
- String filePath) throws FileManagerException {
- return false;
- }
-
- /**
- * Method to retrieve file transfer status giving transfer id
- *
- * @param transferId
- * @return
- * @throws FileManagerException
- */
- @Override
- public FileTransferRequestModel getFileTransferRequestStatus(String transferId) throws FileManagerException {
- try{
- return fileTransferRequestDao.getFileTransferRequest(transferId);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
-
- //TODO API Call to Credential Store
- private SSHCredential getCredential(String credentialStoreToken) throws FileManagerException{
- try{
- SSHCredential sshCredential = new SSHCredential();
- File privateKey = new File("/Users/supun/.ssh/id_rsa");
- byte[] privateKeyBytes = IOUtils.toByteArray(new FileInputStream(privateKey));
- File publicKey = new File("/Users/supun/.ssh/id_rsa.pub");
- byte[] publicKeyBytes = IOUtils.toByteArray(new FileInputStream(publicKey));
- String passPhrase = "cecilia@1990";
- sshCredential.setPrivateKey(privateKeyBytes);
- sshCredential.setPublicKey(publicKeyBytes);
- sshCredential.setPassphrase(passPhrase);
- return sshCredential;
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
- public static void main(String[] args) throws IOException, FileManagerException {
- FileTransferServiceImpl fileTransferService = new FileTransferServiceImpl();
- String sourceFile = "fsgsdgsdgsdgsdg";
- String transferId = fileTransferService.uploadFile("default", "supun", sourceFile.getBytes(), "gw75.iu.xsede.org",
- "pga", 22, StorageResourceProtocol.SCP, "/var/www/portals/test.file", null);
- FileTransferRequestModel fileTransferRequestModel = fileTransferService.fileTransferRequestDao.getFileTransferRequest(transferId);
- System.out.println("file transfer id:" + fileTransferRequestModel.getTransferId());
-
- transferId = fileTransferService.transferFile("default", "supun", "gw75.iu.xsede.org", "pga", 22, StorageResourceProtocol.SCP,
- "/var/www/portals/test.file", null, "gw75.iu.xsede.org", "pga", 22, StorageResourceProtocol.SCP,
- "/var/www/portals/test2.file", null);
- fileTransferRequestModel = fileTransferService.fileTransferRequestDao.getFileTransferRequest(transferId);
- System.out.println("file transfer id:" + fileTransferRequestModel.getTransferId());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/MetadataCatalogService.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/MetadataCatalogService.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/MetadataCatalogService.java
deleted file mode 100644
index 5c09de5..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/MetadataCatalogService.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core;
-
-import org.apache.airavata.file.manager.cpi.FileManagerException;
-import org.apache.airavata.model.file.metadata.MetadataModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MetadataCatalogService implements org.apache.airavata.file.manager.cpi.MetadataCatalogService{
- private final static Logger logger = LoggerFactory.getLogger(MetadataCatalogService.class);
-
- /**
- * Create new metadata model
- *
- * @param metadataModel
- * @return
- * @throws FileManagerException
- */
- @Override
- public String createMetadata(MetadataModel metadataModel) throws FileManagerException {
- return null;
- }
-
- /**
- * Update existing metadata model
- *
- * @param metadataModel
- * @throws FileManagerException
- */
- @Override
- public void updateMetadata(MetadataModel metadataModel) throws FileManagerException {
-
- }
-
- /**
- * Delete existing metadata model
- *
- * @param metadataId
- * @throws FileManagerException
- */
- @Override
- public void deleteMetadata(String metadataId) throws FileManagerException {
-
- }
-
- /**
- * Retrieve metadata model
- *
- * @param metadataId
- * @return
- * @throws FileManagerException
- */
- @Override
- public MetadataModel getMetadata(String metadataId) throws FileManagerException {
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/MetadataCatalogServiceImpl.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/MetadataCatalogServiceImpl.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/MetadataCatalogServiceImpl.java
deleted file mode 100644
index b2a3dda..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/MetadataCatalogServiceImpl.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core;
-
-import org.apache.airavata.file.manager.core.db.dao.MetadataDao;
-import org.apache.airavata.file.manager.cpi.FileManagerException;
-import org.apache.airavata.model.file.metadata.MetadataModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-public class MetadataCatalogServiceImpl extends MetadataCatalogService {
- private final static Logger logger = LoggerFactory.getLogger(MetadataCatalogServiceImpl.class);
-
- private MetadataDao metadataDao;
-
- public MetadataCatalogServiceImpl() throws IOException {
- this.metadataDao = new MetadataDao();
- }
-
- /**
- * Create new metadata model
- *
- * @param metadataModel
- * @return
- * @throws FileManagerException
- */
- @Override
- public String createMetadata(MetadataModel metadataModel) throws FileManagerException {
- try{
- return metadataDao.createMetadata(metadataModel);
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new FileManagerException(e);
- }
- }
-
- /**
- * Update exisiting metadata model
- *
- * @param metadataModel
- * @throws FileManagerException
- */
- @Override
- public void updateMetadata(MetadataModel metadataModel) throws FileManagerException {
- try{
- metadataDao.updateMetadata(metadataModel);
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new FileManagerException(e);
- }
- }
-
- /**
- * Delete existing metadata model
- *
- * @param metadataId
- * @throws FileManagerException
- */
- @Override
- public void deleteMetadata(String metadataId) throws FileManagerException {
- try{
- metadataDao.deleteMetadata(metadataId);
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new FileManagerException(e);
- }
- }
-
- /**
- * Retrieve metadata model
- *
- * @param metadataId
- * @return
- * @throws FileManagerException
- */
- @Override
- public MetadataModel getMetadata(String metadataId) throws FileManagerException {
- try{
- return metadataDao.getMetadata(metadataId);
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new FileManagerException(e);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/ReplicaCatalogServiceImpl.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/ReplicaCatalogServiceImpl.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/ReplicaCatalogServiceImpl.java
deleted file mode 100644
index 119e0ae..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/ReplicaCatalogServiceImpl.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core;
-
-import org.apache.airavata.file.manager.core.db.dao.FileCollectionDao;
-import org.apache.airavata.file.manager.core.db.dao.FileDao;
-import org.apache.airavata.file.manager.cpi.FileManagerException;
-import org.apache.airavata.file.manager.cpi.ReplicaCatalogService;
-import org.apache.airavata.model.file.replica.FileCollectionModel;
-import org.apache.airavata.model.file.replica.FileModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-public class ReplicaCatalogServiceImpl implements ReplicaCatalogService {
- private final static Logger logger = LoggerFactory.getLogger(ReplicaCatalogServiceImpl.class);
-
- private FileDao fileDao;
- private FileCollectionDao fileCollectionDao;
-
- public ReplicaCatalogServiceImpl() throws IOException {
- this.fileDao = new FileDao();
- this.fileCollectionDao = new FileCollectionDao();
- }
-
- /**
- * Creates a new file entry in the replica catalog
- *
- * @param fileModel
- * @return
- */
- @Override
- public String registerFileDetails(FileModel fileModel) throws FileManagerException {
- try{
- return fileDao.createFile(fileModel);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
- /**
- * Updates an existing file information
- *
- * @param fileModel
- */
- @Override
- public void updateFileDetails(FileModel fileModel) throws FileManagerException {
- try{
- fileDao.updateFile(fileModel);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
- /**
- * Deletes the specified file details entry
- *
- * @param fileId
- */
- @Override
- public void deleteFileDetails(String fileId) throws FileManagerException {
- try{
- fileDao.deleteFile(fileId);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
- /**
- * Retrieves file details for the specified file id
- *
- * @param fileId
- * @return
- */
- @Override
- public FileModel getFileDetails(String fileId) throws FileManagerException {
- try{
- return fileDao.getFile(fileId);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
- /**
- * Create new file collection entry
- *
- * @param fileCollectionModel
- * @return
- * @throws FileManagerException
- */
- @Override
- public String registerFileCollection(FileCollectionModel fileCollectionModel) throws FileManagerException {
- try{
- return fileCollectionDao.createFileCollection(fileCollectionModel);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
- /**
- * Update existing file collection
- *
- * @param fileCollectionModel
- * @throws FileManagerException
- */
- @Override
- public void updateFileCollection(FileCollectionModel fileCollectionModel) throws FileManagerException {
- try{
- fileCollectionDao.updateFileCollection(fileCollectionModel);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
- /**
- * Delete exisiting file collection
- *
- * @param collectionId
- * @throws FileManagerException
- */
- @Override
- public void deleteFileCollection(String collectionId) throws FileManagerException {
- try{
- fileCollectionDao.deleteFileCollection(collectionId);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-
- /**
- * Retrieve file collection specifying the collection id
- *
- * @param collectionId
- * @return
- * @throws FileManagerException
- */
- @Override
- public FileCollectionModel getFileCollection(String collectionId) throws FileManagerException {
- try{
- return fileCollectionDao.getFileCollection(collectionId);
- }catch (Exception ex){
- logger.error(ex.getMessage(), ex);
- throw new FileManagerException(ex);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/AbstractThriftDeserializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/AbstractThriftDeserializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/AbstractThriftDeserializer.java
deleted file mode 100644
index a50e0ea..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/AbstractThriftDeserializer.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.*;
-import com.fasterxml.jackson.databind.node.JsonNodeType;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.fasterxml.jackson.databind.type.TypeFactory;
-import com.google.common.base.CaseFormat;
-import org.apache.thrift.TBase;
-import org.apache.thrift.TException;
-import org.apache.thrift.TFieldIdEnum;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.ParameterizedType;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * This abstract class represents a generic de-serializer for converting JSON to Thrift-based entities.
- *
- * @param <E> An implementation of the {@link org.apache.thrift.TFieldIdEnum} interface.
- * @param <T> An implementation of the {@link org.apache.thrift.TBase} interface.
- */
-public abstract class AbstractThriftDeserializer<E extends TFieldIdEnum, T extends TBase<T, E>> extends JsonDeserializer<T> {
-
- private static Logger log = LoggerFactory.getLogger(AbstractThriftDeserializer.class);
-
- @Override
- public T deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
- final T instance = newInstance();
- final ObjectMapper mapper = (ObjectMapper)jp.getCodec();
- final ObjectNode rootNode = (ObjectNode)mapper.readTree(jp);
- final Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.fields();
-
- while(iterator.hasNext()) {
- final Map.Entry<String, JsonNode> currentField = iterator.next();
- try {
- /*
- * If the current node is not a null value, process it. Otherwise,
- * skip it. Jackson will treat the null as a 0 for primitive
- * number types, which in turn will make Thrift think the field
- * has been set. Also we ignore the MongoDB specific _id field
- */
- if(currentField.getValue().getNodeType() != JsonNodeType.NULL) {
- final E field = getField(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, currentField.getKey()));
- final JsonParser parser = currentField.getValue().traverse();
- parser.setCodec(mapper);
- final Object value = mapper.readValue(parser, generateValueType(instance, field));
- if(value != null) {
- log.debug(String.format("Field %s produced value %s of type %s.",
- currentField.getKey(), value, value.getClass().getName()));
- instance.setFieldValue(field, value);
- } else {
- log.debug("Field {} contains a null value. Skipping...", currentField.getKey());
- }
- } else {
- log.debug("Field {} contains a null value. Skipping...", currentField.getKey());
- }
- } catch (final NoSuchFieldException | IllegalArgumentException e) {
- log.error("Unable to de-serialize field '{}'.", currentField.getKey(), e);
- ctxt.mappingException(e.getMessage());
- }
- }
-
- try {
- // Validate that the instance contains all required fields.
- validate(instance);
- } catch (final TException e) {
- log.error(String.format("Unable to deserialize JSON '%s' to type '%s'.",
- jp.getValueAsString(), instance.getClass().getName(), e));
- ctxt.mappingException(e.getMessage());
- }
-
- return instance;
- }
-
- /**
- * Returns the {@code <E>} enumerated value that represents the target
- * field in the Thrift entity referenced in the JSON document.
- * @param fieldName The name of the Thrift entity target field.
- * @return The {@code <E>} enumerated value that represents the target
- * field in the Thrift entity referenced in the JSON document.
- */
- protected abstract E getField(String fieldName);
-
- /**
- * Creates a new instance of the Thrift entity class represented by this deserializer.
- * @return A new instance of the Thrift entity class represented by this deserializer.
- */
- protected abstract T newInstance();
-
- /**
- * Validates that the Thrift entity instance contains all required fields after deserialization.
- * @param instance A Thrift entity instance.
- * @throws org.apache.thrift.TException if unable to validate the instance.
- */
- protected abstract void validate(T instance) throws TException;
-
- /**
- * Generates a {@link JavaType} that matches the target Thrift field represented by the provided
- * {@code <E>} enumerated value. If the field's type includes generics, the generics will
- * be added to the generated {@link JavaType} to support proper conversion.
- * @param thriftInstance The Thrift-generated class instance that will be converted to/from JSON.
- * @param field A {@code <E>} enumerated value that represents a field in a Thrift-based entity.
- * @return The {@link JavaType} representation of the type associated with the field.
- * @throws NoSuchFieldException if unable to determine the field's type.
- * @throws SecurityException if unable to determine the field's type.
- */
- protected JavaType generateValueType(final T thriftInstance, final E field) throws NoSuchFieldException, SecurityException {
- final TypeFactory typeFactory = TypeFactory.defaultInstance();
-
- final Field declaredField = thriftInstance.getClass().getDeclaredField(field.getFieldName());
- if(declaredField.getType().equals(declaredField.getGenericType())) {
- log.debug("Generating JavaType for type '{}'.", declaredField.getType());
- return typeFactory.constructType(declaredField.getType());
- } else {
- final ParameterizedType type = (ParameterizedType)declaredField.getGenericType();
- final Class<?>[] parameterizedTypes = new Class<?>[type.getActualTypeArguments().length];
- for(int i=0; i<type.getActualTypeArguments().length; i++) {
- parameterizedTypes[i] = (Class<?>)type.getActualTypeArguments()[i];
- }
- log.debug("Generating JavaType for type '{}' with generics '{}'", declaredField.getType(), parameterizedTypes);
- return typeFactory.constructParametricType(declaredField.getType(), parameterizedTypes);
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/AbstractThriftSerializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/AbstractThriftSerializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/AbstractThriftSerializer.java
deleted file mode 100644
index f8be22a..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/AbstractThriftSerializer.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.google.common.base.CaseFormat;
-import org.apache.thrift.TBase;
-import org.apache.thrift.TFieldIdEnum;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.Collection;
-
-/**
- * This abstract class represents a generic serializer for converting Thrift-based entities
- * to JSON.
- *
- * @param <E> An implementation of the {@link org.apache.thrift.TFieldIdEnum} interface.
- * @param <T> An implementation of the {@link org.apache.thrift.TBase} interface.
- */
-public abstract class AbstractThriftSerializer<E extends TFieldIdEnum, T extends TBase<T, E>>
- extends JsonSerializer<T> {
-
- private static final Logger log = LoggerFactory.getLogger(AbstractThriftSerializer.class);
-
- @Override
- public Class<T> handledType() {
- return getThriftClass();
- }
-
- @Override
- public void serialize(final T value, final JsonGenerator jgen, final SerializerProvider provider)
- throws IOException, JsonProcessingException {
- jgen.writeStartObject();
- for(final E field : getFieldValues()) {
- if(value.isSet(field)) {
- final Object fieldValue = value.getFieldValue(field);
- if(fieldValue != null) {
- log.debug("Adding field {} to the JSON string...",
- CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName())
- );
-
- jgen.writeFieldName(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName()));
- if(fieldValue instanceof Short) {
- jgen.writeNumber((Short)fieldValue);
- } else if(fieldValue instanceof Integer) {
- jgen.writeNumber((Integer)fieldValue);
- } else if(fieldValue instanceof Long) {
- jgen.writeNumber((Long)fieldValue);
- } else if(fieldValue instanceof Double) {
- jgen.writeNumber((Double)fieldValue);
- } else if(fieldValue instanceof Float) {
- jgen.writeNumber((Float)fieldValue);
- } else if(fieldValue instanceof Boolean) {
- jgen.writeBoolean((Boolean)fieldValue);
- } else if(fieldValue instanceof String) {
- jgen.writeString(fieldValue.toString());
- } else if(fieldValue instanceof Collection) {
- log.debug("Array opened for field {}.",
- CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName())
- );
- jgen.writeStartArray();
- for(final Object arrayObject : (Collection<?>)fieldValue) {
- jgen.writeObject(arrayObject);
- }
- jgen.writeEndArray();
- log.debug("Array closed for field {}.",
- CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName())
- );
- } else {
- jgen.writeObject(fieldValue);
- }
- } else {
- log.debug("Skipping converting field {} to JSON: value is null!",
- CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName())
- );
- }
- } else {
- log.debug("Skipping converting field {} to JSON: field has not been set!",
- CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName())
- );
- }
- }
- jgen.writeEndObject();
- }
-
- /**
- * Returns an array of {@code <E>} enumerated values that represent the fields present in the
- * Thrift class associated with this serializer.
- * @return The array of {@code <E>} enumerated values that represent the fields present in the
- * Thrift class.
- */
- protected abstract E[] getFieldValues();
-
- /**
- * Returns the {@code <T>} implementation class associated with this serializer.
- * @return The {@code <T>} implementation class
- */
- protected abstract Class<T> getThriftClass();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/ModelConversionHelper.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/ModelConversionHelper.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/ModelConversionHelper.java
deleted file mode 100644
index 9aac5af..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/ModelConversionHelper.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.Version;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import org.apache.airavata.file.manager.core.db.conversion.metadata.MetadataDeserializer;
-import org.apache.airavata.file.manager.core.db.conversion.metadata.MetadataSerializer;
-import org.apache.airavata.file.manager.core.db.conversion.transfer.FileTransferRequestDeserializer;
-import org.apache.airavata.file.manager.core.db.conversion.transfer.FileTransferRequestSerializer;
-import org.apache.airavata.file.manager.core.db.conversion.replica.FileCollectionDeserializer;
-import org.apache.airavata.file.manager.core.db.conversion.replica.FileCollectionSerializer;
-import org.apache.airavata.file.manager.core.db.conversion.replica.FileDeserializer;
-import org.apache.airavata.file.manager.core.db.conversion.replica.FileSerializer;
-import org.apache.airavata.model.file.metadata.MetadataModel;
-import org.apache.airavata.model.file.transfer.FileTransferRequestModel;
-import org.apache.airavata.model.file.replica.FileCollectionModel;
-import org.apache.airavata.model.file.replica.FileModel;
-import org.apache.thrift.TBase;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-
-/**
- * This is utility class for model conversion of thrift to/from json
- */
-public class ModelConversionHelper {
- private final static Logger logger = LoggerFactory.getLogger(ModelConversionHelper.class);
-
- private ObjectMapper objectMapper;
-
- public ModelConversionHelper(){
- init();
- }
-
- /**
- * Private method to register the custom serializers and deserializers
- */
- private void init(){
- this.objectMapper = new ObjectMapper();
- SimpleModule module = new SimpleModule("FileManager",
- new Version(1,0,0,null,null,null));
-
- module.addSerializer(FileTransferRequestModel.class, new FileTransferRequestSerializer());
- module.addDeserializer(FileTransferRequestModel.class, new FileTransferRequestDeserializer());
-
- module.addSerializer(FileModel.class, new FileSerializer());
- module.addDeserializer(FileModel.class, new FileDeserializer());
-
- module.addSerializer(FileCollectionModel.class, new FileCollectionSerializer());
- module.addDeserializer(FileCollectionModel.class, new FileCollectionDeserializer());
-
- module.addSerializer(MetadataModel.class, new MetadataSerializer());
- module.addDeserializer(MetadataModel.class, new MetadataDeserializer());
-
- objectMapper.registerModule(module);
- }
-
- /**
- * Method to serialize a thrift object to json
- * @param object
- * @return
- * @throws JsonProcessingException
- */
- public String serializeObject(TBase object) throws JsonProcessingException {
- String json = this.objectMapper.writeValueAsString(object);
- return json;
- }
-
- /**
- * Method to deserialize a json to the thrift object
- * @param clz
- * @param json
- * @return
- * @throws IOException
- */
- public TBase deserializeObject(Class<?> clz, String json) throws IOException {
- return (TBase)this.objectMapper.readValue(json, clz);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/metadata/MetadataDeserializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/metadata/MetadataDeserializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/metadata/MetadataDeserializer.java
deleted file mode 100644
index 8323957..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/metadata/MetadataDeserializer.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion.metadata;
-
-import org.apache.airavata.file.manager.core.db.conversion.AbstractThriftDeserializer;
-import org.apache.airavata.model.file.metadata.MetadataModel;
-import org.apache.airavata.model.file.transfer.FileTransferRequestModel;
-import org.apache.thrift.TException;
-
-public class MetadataDeserializer extends
- AbstractThriftDeserializer<MetadataModel._Fields, MetadataModel> {
-
- @Override
- protected MetadataModel._Fields getField(final String fieldName) {
- return MetadataModel._Fields.valueOf(fieldName);
- }
-
- @Override
- protected MetadataModel newInstance() {
- return new MetadataModel();
- }
-
- @Override
- protected void validate(final MetadataModel instance) throws TException {
- instance.validate();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/metadata/MetadataSerializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/metadata/MetadataSerializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/metadata/MetadataSerializer.java
deleted file mode 100644
index d527290..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/metadata/MetadataSerializer.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion.metadata;
-
-import org.apache.airavata.file.manager.core.db.conversion.AbstractThriftSerializer;
-import org.apache.airavata.model.file.metadata.MetadataModel;
-import org.apache.airavata.model.file.transfer.FileTransferRequestModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MetadataSerializer extends
- AbstractThriftSerializer<MetadataModel._Fields, MetadataModel> {
- private final static Logger logger = LoggerFactory.getLogger(MetadataSerializer.class);
-
- @Override
- protected MetadataModel._Fields[] getFieldValues() {
- return MetadataModel._Fields.values();
- }
-
- @Override
- protected Class<MetadataModel> getThriftClass() {
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileCollectionDeserializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileCollectionDeserializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileCollectionDeserializer.java
deleted file mode 100644
index 2953c70..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileCollectionDeserializer.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion.replica;
-
-import org.apache.airavata.file.manager.core.db.conversion.AbstractThriftDeserializer;
-import org.apache.airavata.model.file.replica.FileCollectionModel;
-import org.apache.thrift.TException;
-
-public class FileCollectionDeserializer extends
- AbstractThriftDeserializer<FileCollectionModel._Fields, FileCollectionModel> {
-
- @Override
- protected FileCollectionModel._Fields getField(final String fieldName) {
- return FileCollectionModel._Fields.valueOf(fieldName);
- }
-
- @Override
- protected FileCollectionModel newInstance() {
- return new FileCollectionModel();
- }
-
- @Override
- protected void validate(final FileCollectionModel instance) throws TException {
- instance.validate();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileCollectionSerializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileCollectionSerializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileCollectionSerializer.java
deleted file mode 100644
index a57363c..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileCollectionSerializer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion.replica;
-
-import org.apache.airavata.file.manager.core.db.conversion.AbstractThriftSerializer;
-import org.apache.airavata.model.file.replica.FileCollectionModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FileCollectionSerializer extends
- AbstractThriftSerializer<FileCollectionModel._Fields, FileCollectionModel> {
- private final static Logger logger = LoggerFactory.getLogger(FileCollectionSerializer.class);
-
- @Override
- protected FileCollectionModel._Fields[] getFieldValues() {
- return FileCollectionModel._Fields.values();
- }
-
- @Override
- protected Class<FileCollectionModel> getThriftClass() {
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileDeserializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileDeserializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileDeserializer.java
deleted file mode 100644
index ba43ca1..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileDeserializer.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion.replica;
-
-import org.apache.airavata.file.manager.core.db.conversion.AbstractThriftDeserializer;
-import org.apache.airavata.model.file.replica.FileModel;
-import org.apache.thrift.TException;
-
-public class FileDeserializer extends
- AbstractThriftDeserializer<FileModel._Fields, FileModel> {
-
- @Override
- protected FileModel._Fields getField(final String fieldName) {
- return FileModel._Fields.valueOf(fieldName);
- }
-
- @Override
- protected FileModel newInstance() {
- return new FileModel();
- }
-
- @Override
- protected void validate(final FileModel instance) throws TException {
- instance.validate();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileSerializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileSerializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileSerializer.java
deleted file mode 100644
index eeb5c01..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/replica/FileSerializer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion.replica;
-
-import org.apache.airavata.file.manager.core.db.conversion.AbstractThriftSerializer;
-import org.apache.airavata.model.file.replica.FileModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FileSerializer extends
- AbstractThriftSerializer<FileModel._Fields, FileModel> {
- private final static Logger logger = LoggerFactory.getLogger(FileSerializer.class);
-
- @Override
- protected FileModel._Fields[] getFieldValues() {
- return FileModel._Fields.values();
- }
-
- @Override
- protected Class<FileModel> getThriftClass() {
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/transfer/FileTransferRequestDeserializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/transfer/FileTransferRequestDeserializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/transfer/FileTransferRequestDeserializer.java
deleted file mode 100644
index 93d200c..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/transfer/FileTransferRequestDeserializer.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion.transfer;
-
-import org.apache.airavata.file.manager.core.db.conversion.AbstractThriftDeserializer;
-import org.apache.airavata.model.file.transfer.FileTransferRequestModel;
-import org.apache.thrift.TException;
-
-public class FileTransferRequestDeserializer extends
- AbstractThriftDeserializer<FileTransferRequestModel._Fields, FileTransferRequestModel> {
-
- @Override
- protected FileTransferRequestModel._Fields getField(final String fieldName) {
- return FileTransferRequestModel._Fields.valueOf(fieldName);
- }
-
- @Override
- protected FileTransferRequestModel newInstance() {
- return new FileTransferRequestModel();
- }
-
- @Override
- protected void validate(final FileTransferRequestModel instance) throws TException {
- instance.validate();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/transfer/FileTransferRequestSerializer.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/transfer/FileTransferRequestSerializer.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/transfer/FileTransferRequestSerializer.java
deleted file mode 100644
index 4e4dc70..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/conversion/transfer/FileTransferRequestSerializer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.conversion.transfer;
-
-import org.apache.airavata.file.manager.core.db.conversion.AbstractThriftSerializer;
-import org.apache.airavata.model.file.transfer.FileTransferRequestModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FileTransferRequestSerializer extends
- AbstractThriftSerializer<FileTransferRequestModel._Fields, FileTransferRequestModel> {
- private final static Logger logger = LoggerFactory.getLogger(FileTransferRequestSerializer.class);
-
- @Override
- protected FileTransferRequestModel._Fields[] getFieldValues() {
- return FileTransferRequestModel._Fields.values();
- }
-
- @Override
- protected Class<FileTransferRequestModel> getThriftClass() {
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileCollectionDao.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileCollectionDao.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileCollectionDao.java
deleted file mode 100644
index c9d29d6..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileCollectionDao.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.dao;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.mongodb.*;
-import com.mongodb.util.JSON;
-import org.apache.airavata.file.manager.core.db.conversion.ModelConversionHelper;
-import org.apache.airavata.file.manager.core.db.utils.MongoUtils;
-import org.apache.airavata.file.manager.cpi.FileManagerConstants;
-import org.apache.airavata.model.file.replica.FileCollectionModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.UUID;
-
-public class FileCollectionDao {
- private final static Logger logger = LoggerFactory.getLogger(FileCollectionDao.class);
-
- private static final String FILE_COLLECTION_COLLECTION_NAME = "collection-models";
- private DBCollection collection;
- private ModelConversionHelper modelConversionHelper;
-
- private static final String COLLECTION_ID = "collection_id";
-
- public FileCollectionDao() throws IOException {
- collection = MongoUtils.getFileManagerRegistry().getCollection(FILE_COLLECTION_COLLECTION_NAME);
- modelConversionHelper = new ModelConversionHelper();
- collection.dropIndexes();
- initIndexes();
- }
-
- /**
- * If indexes are already defined this will simply ignore them
- */
- private void initIndexes() {
- collection.createIndex(new BasicDBObject(COLLECTION_ID, 1), new BasicDBObject("unique", true));
- }
-
- public String createFileCollection(FileCollectionModel fileCollectionModel) throws JsonProcessingException {
- fileCollectionModel.setCollectionId(FileManagerConstants.AIRAVATA_COLLECTION_ID_PREFIX + UUID.randomUUID().toString());
- WriteResult result = collection.insert((DBObject) JSON.parse(
- modelConversionHelper.serializeObject(fileCollectionModel)));
- logger.debug("No of inserted results " + result.getN());
- return fileCollectionModel.getCollectionId();
- }
-
- public void updateFileCollection(FileCollectionModel fileCollectionModel) throws JsonProcessingException {
- DBObject query = BasicDBObjectBuilder.start().add(
- COLLECTION_ID, fileCollectionModel.getCollectionId()).get();
- WriteResult result = collection.update(query, (DBObject) JSON.parse(
- modelConversionHelper.serializeObject(fileCollectionModel)));
- logger.debug("No of updated results " + result.getN());
- }
-
- public void deleteFileCollection(String collectionId){
- DBObject query = BasicDBObjectBuilder.start().add(
- COLLECTION_ID,collectionId).get();
- WriteResult result = collection.remove(query);
- logger.debug("No of removed file model requests " + result.getN());
- }
-
- public FileCollectionModel getFileCollection(String collectionId) throws IOException {
-
- DBObject criteria = new BasicDBObject(COLLECTION_ID, collectionId);
- DBObject doc = collection.findOne(criteria);
- if (doc != null) {
- String json = doc.toString();
- return (FileCollectionModel) modelConversionHelper.deserializeObject(
- FileCollectionModel.class, json);
- }
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileDao.java
----------------------------------------------------------------------
diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileDao.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileDao.java
deleted file mode 100644
index ac6a1df..0000000
--- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileDao.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.file.manager.core.db.dao;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.mongodb.*;
-import com.mongodb.util.JSON;
-import org.apache.airavata.file.manager.core.db.conversion.ModelConversionHelper;
-import org.apache.airavata.file.manager.core.db.utils.MongoUtils;
-import org.apache.airavata.file.manager.cpi.FileManagerConstants;
-import org.apache.airavata.model.file.replica.FileModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.UUID;
-
-public class FileDao {
- private final static Logger logger = LoggerFactory.getLogger(FileDao.class);
-
- private static final String FILE_MODELS_COLLECTION_NAME = "file-models";
- private DBCollection collection;
- private ModelConversionHelper modelConversionHelper;
-
- private static final String FILE_ID = "file_id";
-
- public FileDao() throws IOException {
- collection = MongoUtils.getFileManagerRegistry().getCollection(FILE_MODELS_COLLECTION_NAME);
- modelConversionHelper = new ModelConversionHelper();
- collection.dropIndexes();
- initIndexes();
- }
-
- /**
- * If indexes are already defined this will simply ignore them
- */
- private void initIndexes() {
- collection.createIndex(new BasicDBObject(FILE_ID, 1), new BasicDBObject("unique", true));
- }
-
- public String createFile(FileModel fileModel) throws JsonProcessingException {
- fileModel.setFileId(FileManagerConstants.AIRAVATA_FILE_ID_PREFIX + UUID.randomUUID().toString());
- WriteResult result = collection.insert((DBObject) JSON.parse(
- modelConversionHelper.serializeObject(fileModel)));
- logger.debug("No of inserted results " + result.getN());
- return fileModel.getFileId();
- }
-
- public void updateFile(FileModel fileModel) throws JsonProcessingException {
- DBObject query = BasicDBObjectBuilder.start().add(
- FILE_ID, fileModel.getFileId()).get();
- WriteResult result = collection.update(query, (DBObject) JSON.parse(
- modelConversionHelper.serializeObject(fileModel)));
- logger.debug("No of updated results " + result.getN());
- }
-
- public void deleteFile(String fileId){
- DBObject query = BasicDBObjectBuilder.start().add(
- FILE_ID,fileId).get();
- WriteResult result = collection.remove(query);
- logger.debug("No of removed file model requests " + result.getN());
- }
-
- public FileModel getFile(String fileId) throws IOException {
-
- DBObject criteria = new BasicDBObject(FILE_ID, fileId);
- DBObject doc = collection.findOne(criteria);
- if (doc != null) {
- String json = doc.toString();
- return (FileModel) modelConversionHelper.deserializeObject(
- FileModel.class, json);
- }
- return null;
- }
-}
\ No newline at end of file