Search in sources :

Example 81 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class RuleDeploymentServiceImpl method deployRule.

@Override
public void deployRule(MultipartFile file) throws DataGridException, JargonException {
    logger.info("Deploying rule");
    if (file == null) {
        logger.error("File could not be sent to the data grid. Rule file is null.");
        throw new DataGridException("Rule file is null.");
    }
    if (!ruleCacheExists()) {
        logger.info("Rule cache does not exist. Creating one.");
        createRuleCache();
    }
    InputStream inputStream;
    try {
        inputStream = file.getInputStream();
    } catch (IOException e) {
        logger.error("Could not get input stream from rule file: ", e.getMessage());
        throw new DataGridException("Could not get input stream from ruleFile.");
    }
    // Getting DataObjectAO in order to create the new rule file
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    Stream2StreamAO stream2StreamA0 = irodsServices.getStream2StreamAO();
    IRODSFile targetFile = null;
    try {
        String ruleCacheDirPath = getRuleCachePath();
        String ruleName = file.getOriginalFilename().isEmpty() ? file.getName() : file.getOriginalFilename();
        targetFile = irodsFileFactory.instanceIRODSFile(ruleCacheDirPath, ruleName);
        stream2StreamA0.transferStreamToFileUsingIOStreams(inputStream, (File) targetFile, 0, BUFFER_SIZE);
        String resourceName = irodsServices.getDefaultStorageResource();
        Resource resc = irodsServices.getResourceAO().findByName(resourceName);
        String vaultPath = resc.getVaultPath();
        String host = resc.getLocation();
        String ruleVaultPath = String.format("%s/%s/%s", vaultPath, RULE_CACHE_DIR_NAME, ruleName);
        String ruleNameWithoutExtension = FilenameUtils.removeExtension(ruleName);
        ruleService.execDeploymentRule(host, ruleNameWithoutExtension, ruleVaultPath);
    } catch (JargonException e) {
        if (targetFile != null)
            fos.deleteDataObject(targetFile.getPath(), true);
        logger.error("Upload stream failed from Metalnx to the data grid. {}", e.getMessage());
        throw new DataGridException("Upload failed. Resource(s) might be full.");
    } finally {
        try {
            // Closing streams opened
            inputStream.close();
        } catch (IOException e) {
            logger.error("Could close stream: ", e.getMessage());
        }
    }
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) InputStream(java.io.InputStream) Stream2StreamAO(org.irods.jargon.core.pub.Stream2StreamAO) JargonException(org.irods.jargon.core.exception.JargonException) Resource(org.irods.jargon.core.pub.domain.Resource) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 82 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class SpecQueryServiceImpl method searchByMetadata.

@Override
public SpecificQueryResultSet searchByMetadata(List<DataGridMetadataSearch> metadataSearch, String zone, boolean searchAgainstColls, DataGridPageContext pageContext, int offset, int limit) throws DataGridConnectionRefusedException, JargonException {
    SpecificQueryAO specificQueryAO = null;
    SpecificQuery specQuery = null;
    SpecificQueryResultSet queryResultSet = null;
    String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
    try {
        specificQueryAO = adminServices.getSpecificQueryAO();
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildSpecificQueryForMetadataSearch(metadataSearch, zone, searchAgainstColls);
        // Creating Specific Query instance
        SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
        queryDef.setAlias(userSQLAlias);
        queryDef.setSql(query);
        // Creating spec query on iRODS
        specificQueryAO.addSpecificQuery(queryDef);
        specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
        logger.info("Specific query: {}", query.toString());
        queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
    } catch (JargonException e) {
        logger.error("Could not get specific query: ", e);
        throw e;
    } catch (JargonQueryException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    } catch (UnsupportedDataGridFeatureException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    } finally {
        try {
            // after running the user specific query, we need to remove from the database
            specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
        } catch (JargonException e) {
            logger.error("Could not remove specific query {}: ", userSQLAlias, e.getMessage());
        }
    }
    return queryResultSet;
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) SpecificQueryProvider(com.emc.metalnx.services.irods.utils.SpecificQueryProvider) JargonException(org.irods.jargon.core.exception.JargonException) ClientHints(org.irods.jargon.core.pub.domain.ClientHints) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) SpecificQuery(org.irods.jargon.core.query.SpecificQuery) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition)

Example 83 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class SpecQueryServiceImpl method deleteSpecQueryByAlias.

@Override
public void deleteSpecQueryByAlias(String specQueryAlias) throws DataGridConnectionRefusedException {
    SpecificQueryAO specificQueryAO = null;
    try {
        specificQueryAO = adminServices.getSpecificQueryAO();
        specificQueryAO.removeSpecificQueryByAlias(specQueryAlias);
    } catch (JargonException e) {
        logger.error("Could not get specific query: ", e.getMessage());
    }
}
Also used : JargonException(org.irods.jargon.core.exception.JargonException) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO)

Example 84 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class UserServiceImpl method updateWritePermissions.

@Override
public boolean updateWritePermissions(DataGridUser user, Map<String, Boolean> addCollectionsToWrite, Map<String, Boolean> removeCollectionsToWrite) throws DataGridConnectionRefusedException {
    CollectionAO collectionAO = null;
    DataObjectAO dataObjectAO = null;
    IRODSFile irodsFile = null;
    IRODSFileFactory irodsFileFactory = null;
    boolean writePermissionsUpdated = false;
    try {
        collectionAO = irodsServices.getCollectionAO();
        dataObjectAO = irodsServices.getDataObjectAO();
        irodsFileFactory = irodsServices.getIRODSFileFactory();
        for (String path : addCollectionsToWrite.keySet()) {
            irodsFile = irodsFileFactory.instanceIRODSFile(path);
            if (irodsFile.isDirectory()) {
                collectionAO.setAccessPermissionWriteAsAdmin(user.getAdditionalInfo(), path, user.getUsername(), addCollectionsToWrite.get(path));
            } else {
                dataObjectAO.setAccessPermissionWriteInAdminMode(user.getAdditionalInfo(), path, user.getUsername());
            }
        }
        removeAccessPermissionForUserAsAdmin(user, removeCollectionsToWrite);
        writePermissionsUpdated = true;
    } catch (JargonException e) {
        logger.error("Could not set write permission:", e);
    }
    return writePermissionsUpdated;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 85 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class UserServiceImpl method modifyUser.

@Override
public boolean modifyUser(DataGridUser modifyUser) throws DataGridConnectionRefusedException {
    UserAO userAO = irodsServices.getUserAO();
    try {
        User iRodsUser = userAO.findById(String.valueOf(modifyUser.getDataGridId()));
        boolean iRodsFieldsModified = false;
        // check which fields were modified (iRODS)
        if (iRodsUser.getZone().compareTo(modifyUser.getAdditionalInfo()) != 0) {
            iRodsUser.setZone(modifyUser.getAdditionalInfo());
            iRodsFieldsModified = true;
        }
        if (!iRodsUser.getUserType().getTextValue().equals(modifyUser.getUserType())) {
            if (modifyUser.getUserType().compareTo(UserTypeEnum.RODS_ADMIN.getTextValue()) == 0) {
                iRodsUser.setUserType(UserTypeEnum.RODS_ADMIN);
            } else {
                iRodsUser.setUserType(UserTypeEnum.RODS_USER);
            }
            iRodsFieldsModified = true;
        }
        // updating user in iRODS if any field was modified
        if (iRodsFieldsModified) {
            userAO.updateUser(iRodsUser);
        }
        DataGridUser applicationUser = userDao.findByUsernameAndZone(modifyUser.getUsername(), modifyUser.getAdditionalInfo());
        // check which fields were modified (our database)
        if (applicationUser.getAdditionalInfo() == null || applicationUser.getAdditionalInfo().compareTo(modifyUser.getAdditionalInfo()) != 0) {
            applicationUser.setAdditionalInfo(modifyUser.getAdditionalInfo());
        }
        if (applicationUser.getFirstName() == null || applicationUser.getFirstName().compareTo(modifyUser.getFirstName()) != 0) {
            applicationUser.setFirstName(modifyUser.getFirstName());
        }
        if (applicationUser.getLastName() == null || applicationUser.getLastName().compareTo(modifyUser.getLastName()) != 0) {
            applicationUser.setLastName(modifyUser.getLastName());
        }
        if (applicationUser.getEmail() == null || applicationUser.getEmail().compareTo(modifyUser.getEmail()) != 0) {
            applicationUser.setEmail(modifyUser.getEmail());
        }
        if (applicationUser.getCompany() == null || applicationUser.getCompany().compareTo(modifyUser.getCompany()) != 0) {
            applicationUser.setCompany(modifyUser.getCompany());
        }
        if (applicationUser.getDepartment() == null || applicationUser.getDepartment().compareTo(modifyUser.getDepartment()) != 0) {
            applicationUser.setDepartment(modifyUser.getDepartment());
        }
        applicationUser.setUserProfile(modifyUser.getUserProfile());
        applicationUser.setLocale(modifyUser.getLocale());
        applicationUser.setOrganizationalRole(modifyUser.getOrganizationalRole());
        applicationUser.setUserType(modifyUser.getUserType());
        applicationUser.setForceFileOverwriting(modifyUser.isForceFileOverwriting());
        applicationUser.setAdvanceView(modifyUser.isAdvancedView());
        userDao.merge(applicationUser);
        // Changing password if a new password is set
        String newPassword = modifyUser.getPassword();
        if (newPassword != null && !newPassword.isEmpty()) {
            userAO.changeAUserPasswordByAnAdmin(modifyUser.getUsername(), newPassword);
        }
        return true;
    } catch (JargonException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) JargonException(org.irods.jargon.core.exception.JargonException) UserAO(org.irods.jargon.core.pub.UserAO)

Aggregations

JargonException (org.irods.jargon.core.exception.JargonException)86 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)20 CollectionAO (org.irods.jargon.core.pub.CollectionAO)20 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)18 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)18 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)17 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)15 ArrayList (java.util.ArrayList)12 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)12 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)11 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)10 SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)10 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)9 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)8 SpecificQueryProvider (com.emc.metalnx.services.irods.utils.SpecificQueryProvider)8 ClientHints (org.irods.jargon.core.pub.domain.ClientHints)8 DataObject (org.irods.jargon.core.pub.domain.DataObject)8 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)8 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8