Search in sources :

Example 1 with DataTypeResolutionService

use of org.irods.jargon.extensions.datatyper.DataTypeResolutionService 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)

Aggregations

DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)1 JargonException (org.irods.jargon.core.exception.JargonException)1 DataTypeResolutionService (org.irods.jargon.extensions.datatyper.DataTypeResolutionService)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1