Search in sources :

Example 31 with JargonException

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

the class SpecQueryServiceImpl method countItemsMatchingMetadata.

/**
 * Counts the number of items matching a metadata search criteria.
 *
 * @param metadataSearch
 *            metadata criteria
 * @param zone
 *            zone name
 * @param searchAgainstColls
 *            flag set to true when searching collections and false when
 *            searching data data objects
 * @return total number of items matching a metadata search criteria
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 */
private int countItemsMatchingMetadata(List<DataGridMetadataSearch> metadataSearch, String zone, boolean searchAgainstColls) throws DataGridConnectionRefusedException, JargonException {
    int totalItems = 0;
    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.buildQueryForCountOfItemsMatchingMetadataSearch(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);
        // after running the user specific query, we need to remove from the database
        specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
        totalItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
    } 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);
    }
    return totalItems;
}
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 32 with JargonException

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

the class UploadServiceImpl method upload.

@Override
public boolean upload(MultipartFile file, String targetPath, boolean computeCheckSum, boolean replicateFile, String replicationResc, String destResc, boolean overwrite) throws DataGridException {
    logger.info("upload()");
    if (file == null || file.isEmpty() || "".equals(targetPath) || targetPath == null || "".equals(destResc) || destResc == null) {
        logger.error("File could not be sent to the data grid.");
        return false;
    }
    logger.info("file:{}", file);
    logger.info("targetPath:{}", targetPath);
    logger.info("computeCheckSum:{}", computeCheckSum);
    logger.info("replicateFile:{}", replicateFile);
    logger.info("replicationResc:{}", replicationResc);
    logger.info("destResc:{}", destResc);
    logger.info("overwrite:{}", overwrite);
    InputStream inputStream;
    try {
        inputStream = file.getInputStream();
    } catch (IOException e) {
        logger.error("Could not get input stream from file: ", e.getMessage());
        throw new DataGridException("Could not get input stream from file.");
    }
    String defaultStorageResource = is.getDefaultStorageResource();
    logger.info("Setting default resource to {}", destResc);
    // Setting temporarily the defaultStorageResource for the logged user
    is.setDefaultStorageResource(destResc);
    boolean isFileUploaded;
    // Getting DataObjectAO in order to create the new file
    IRODSFileFactory irodsFileFactory = is.getIRODSFileFactory();
    Stream2StreamAO stream2StreamA0 = is.getStream2StreamAO();
    IRODSFile targetFile = null;
    try {
        String fileName = file.getOriginalFilename();
        if (fileName.isEmpty())
            fileName = file.getName();
        targetFile = irodsFileFactory.instanceIRODSFile(targetPath, fileName);
        logger.info("targetFile:{}", targetFile);
        // aborted.
        if (targetFile.exists() && !overwrite) {
            String msg = "File already exists. Not overwriting it.";
            logger.info(msg);
            throw new DataGridFileAlreadyExistsException(msg);
        }
        // Transfering file to iRODS filesystem
        stream2StreamA0.transferStreamToFileUsingIOStreams(inputStream, (File) targetFile, 0, BUFFER_SIZE);
        logger.info("transfer complete, compute checksum if required");
        // Computing a check sum for this file just uploaded to iRODS
        if (computeCheckSum)
            fos.computeChecksum(targetPath, fileName);
        // Replicating file into desired resource
        if (replicateFile)
            fos.replicateDataObject(targetFile.getPath(), replicationResc, false);
        if (configService.isUploadRulesEnabled()) {
            logger.info("applying upload rules");
            processUploadRules(targetPath, destResc, targetFile);
        }
        isFileUploaded = true;
    } catch (JargonException e) {
        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.");
    } catch (DataGridFileAlreadyExistsException e) {
        logger.warn("File already exists..will rethrow.");
        throw e;
    } catch (Throwable e) {
        logger.error("Exception in upload processing", e);
        throw new DataGridException("Could not upload due to system exception");
    } finally {
        try {
            // Closing streams opened
            inputStream.close();
        } catch (IOException e) {
            logger.error("Could close stream: ", e.getMessage());
        }
    }
    // Setting the default resource back to the original one.
    is.setDefaultStorageResource(defaultStorageResource);
    return isFileUploaded;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridFileAlreadyExistsException(com.emc.metalnx.core.domain.exceptions.DataGridFileAlreadyExistsException) InputStream(java.io.InputStream) Stream2StreamAO(org.irods.jargon.core.pub.Stream2StreamAO) JargonException(org.irods.jargon.core.exception.JargonException) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 33 with JargonException

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

the class ZoneServiceImpl method findAll.

@Override
public List<DataGridZone> findAll() throws DataGridConnectionRefusedException {
    ZoneAO zoneAO = irodsServices.getZoneAO();
    List<DataGridZone> dataGridZones = null;
    try {
        List<Zone> zones = zoneAO.listZones();
        dataGridZones = new ArrayList<DataGridZone>();
        for (Zone zone : zones) {
            DataGridZone dataGridZone = new DataGridZone();
            dataGridZone.setId(Long.valueOf(zone.getZoneId()));
            dataGridZone.setName(zone.getZoneName());
            dataGridZone.setType(zone.getZoneType());
            dataGridZone.setCreateTime(zone.getZoneCreateTime());
            dataGridZone.setModifyTime(zone.getZoneModifyTime());
            dataGridZone.setConnectionString(zone.getZoneConnection());
            dataGridZone.setComment(zone.getZoneComment());
            // adding this current zone to the list
            dataGridZones.add(dataGridZone);
        }
    } catch (JargonException e) {
        logger.info("Could not find all zones ", e);
    }
    return dataGridZones;
}
Also used : DataGridZone(com.emc.metalnx.core.domain.entity.DataGridZone) Zone(org.irods.jargon.core.pub.domain.Zone) DataGridZone(com.emc.metalnx.core.domain.entity.DataGridZone) JargonException(org.irods.jargon.core.exception.JargonException) ZoneAO(org.irods.jargon.core.pub.ZoneAO)

Example 34 with JargonException

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

the class PreviewPreparationController method getPreview.

/**
 * Responds the preview/ request
 *
 * @param model
 * @return the collection management template
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 * @throws DataGridException
 */
@RequestMapping(value = "/", method = RequestMethod.GET)
public String getPreview(final Model model, @RequestParam("path") final String path, RedirectAttributes redirectAttributes) throws DataGridException {
    logger.info("prepareForPreview for {} ::" + path);
    String mimeType = null;
    boolean permission = previewService.getPermission(path);
    if (permission) {
        try {
            IRODSAccount irodsAccount = irodsServices.getUserAO().getIRODSAccount();
            DataTypeResolutionService dataTypeResolutionService = dataTypeResolutionServiceFactory.instanceDataTypeResolutionService(irodsAccount);
            logger.info("dataTypeResolutionService created from factory:{}", dataTypeResolutionService);
            logger.info("doing quick check for mime type");
            mimeType = dataTypeResolutionService.quickMimeType(path);
            logger.info("mimetype:{}", mimeType);
            redirectAttributes.addAttribute("path", path);
            redirectAttributes.addAttribute("mimeType", mimeType);
            return "redirect:/preview/templateByMimeType";
        } catch (JargonException e) {
            logger.error("Could not retrieve data from path: {}", path, e);
            throw new DataGridException(e.getMessage());
        } catch (Exception e) {
            logger.error("general exception generating preview", e);
            throw new DataGridException(e.getLocalizedMessage());
        }
    } else {
        return "collections/preview :: noPermission";
    }
}
Also used : DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) JargonException(org.irods.jargon.core.exception.JargonException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) DataTypeResolutionService(org.irods.jargon.extensions.datatyper.DataTypeResolutionService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with JargonException

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

the class FilePropertyServiceImpl method findByFileProperties.

@Override
public List<DataGridCollectionAndDataObject> findByFileProperties(List<DataGridFilePropertySearch> searchList, DataGridPageContext pageContext, int pageNum, int pageSize) throws DataGridConnectionRefusedException, JargonException {
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
    List<DataGridCollectionAndDataObject> dataGridObjects = null;
    List<DataGridCollectionAndDataObject> dataGridCollections = null;
    int totalCollections = 0;
    int totalDataObjects = 0;
    int startIndex = (pageNum - 1) * pageSize;
    int endIndex = (pageNum * pageSize) - 1;
    int endIndexForDataObjs;
    int endIndexForCollections;
    try {
        String zone = irodsServices.getCurrentUserZone();
        totalCollections = specQueryService.countCollectionsMatchingFileProperties(searchList, zone);
        totalDataObjects = specQueryService.countDataObjectsMatchingFileProperties(searchList, zone);
        pageContext.setStartItemNumber(startIndex + 1);
        pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
        dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
        if (endIndex + 1 <= totalCollections) {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
            endIndexForCollections = dataGridCollections.size();
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForCollections - 1);
        } else if (startIndex + 1 > totalCollections) {
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, startIndex - totalCollections, pageSize);
            dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
        } else {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
            endIndexForDataObjs = pageSize - (totalCollections % pageSize);
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, 0, endIndexForDataObjs);
            dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
            endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
        }
    } catch (JargonException | UnsupportedDataGridFeatureException e) {
        logger.error("Could not find data objects by metadata. ", e);
        if (e.getCause() instanceof ConnectException) {
            throw new DataGridConnectionRefusedException();
        }
    }
    this.populateVisibilityForCurrentUser(dataGridCollectionAndDataObjects);
    return dataGridCollectionAndDataObjects;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) ConnectException(java.net.ConnectException)

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