Search in sources :

Example 1 with TicketCreateModeEnum

use of org.irods.jargon.ticket.packinstr.TicketCreateModeEnum in project metalnx-web by irods-contrib.

the class TicketServiceImpl method convertDataGridTicketToTicket.

private Ticket convertDataGridTicketToTicket(DataGridTicket dgTicket) {
    Ticket ticket = new Ticket();
    ticket.setTicketString(dgTicket.getTicketString());
    ticket.setOwnerName(dgTicket.getOwner());
    ticket.setIrodsAbsolutePath(dgTicket.getPath());
    ticket.setTicketString(dgTicket.getTicketString());
    ticket.setExpireTime(dgTicket.getExpirationDate());
    ticket.setUsesLimit(dgTicket.getUsesLimit());
    ticket.setUsesCount(dgTicket.getUsesCount());
    ticket.setWriteByteLimit(dgTicket.getWriteByteLimit());
    ticket.setWriteByteCount(dgTicket.getWriteByteCount());
    ticket.setWriteFileLimit(dgTicket.getWriteFileLimit());
    ticket.setWriteFileCount(dgTicket.getWriteFileCount());
    TicketCreateModeEnum ticketMode;
    if (dgTicket.getType() == DataGridTicket.TicketType.READ)
        ticketMode = TicketCreateModeEnum.READ;
    else if (dgTicket.getType() == DataGridTicket.TicketType.WRITE)
        ticketMode = TicketCreateModeEnum.WRITE;
    else
        ticketMode = TicketCreateModeEnum.UNKNOWN;
    ticket.setType(ticketMode);
    if (dgTicket.isCollection())
        ticket.setObjectType(Ticket.TicketObjectType.COLLECTION);
    return ticket;
}
Also used : TicketCreateModeEnum(org.irods.jargon.ticket.packinstr.TicketCreateModeEnum) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) Ticket(org.irods.jargon.ticket.Ticket)

Example 2 with TicketCreateModeEnum

use of org.irods.jargon.ticket.packinstr.TicketCreateModeEnum in project metalnx-web by irods-contrib.

the class TicketServiceImpl method create.

@Override
public String create(DataGridTicket dgTicket) throws DataGridConnectionRefusedException, DataGridTicketException {
    logger.info("Create ticket");
    if (dgTicket == null) {
        logger.info("Could not create ticket: Null ticket provided.");
        throw new DataGridTicketException("Could not create ticket: null ticket provided.");
    }
    if (dgTicket.getPath().isEmpty()) {
        logger.info("Could not create ticket: Ticket with no path.");
        throw new DataGridTicketException("Could not create ticket: path is empty");
    }
    TicketCreateModeEnum ticketType = TicketCreateModeEnum.UNKNOWN;
    if (dgTicket.getType() == DataGridTicket.TicketType.READ)
        ticketType = TicketCreateModeEnum.READ;
    if (dgTicket.getType() == DataGridTicket.TicketType.WRITE)
        ticketType = TicketCreateModeEnum.WRITE;
    String path = dgTicket.getPath();
    int idxOfSeparator = path.lastIndexOf(GRID_FILE_SEPARATOR);
    String parentPath = path.substring(0, idxOfSeparator);
    String item = path.substring(idxOfSeparator + 1, path.length());
    String ticketString = "";
    try {
        IRODSFile irodsFile = irodsServices.getIRODSFileFactory().instanceIRODSFile(parentPath, item);
        TicketAdminService tas = irodsServices.getTicketAdminService();
        ticketString = tas.createTicket(ticketType, irodsFile, dgTicket.getTicketString());
        // set ticket string created by the grid
        dgTicket.setTicketString(ticketString);
        modify(dgTicket);
    } catch (JargonException e) {
        logger.error("Could not create a ticket: {}", e);
        throw new DataGridTicketException(e.getMessage());
    }
    return ticketString;
}
Also used : TicketCreateModeEnum(org.irods.jargon.ticket.packinstr.TicketCreateModeEnum) JargonException(org.irods.jargon.core.exception.JargonException) DataGridTicketException(com.emc.metalnx.core.domain.exceptions.DataGridTicketException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) TicketAdminService(org.irods.jargon.ticket.TicketAdminService)

Aggregations

TicketCreateModeEnum (org.irods.jargon.ticket.packinstr.TicketCreateModeEnum)2 DataGridTicket (com.emc.metalnx.core.domain.entity.DataGridTicket)1 DataGridTicketException (com.emc.metalnx.core.domain.exceptions.DataGridTicketException)1 JargonException (org.irods.jargon.core.exception.JargonException)1 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)1 Ticket (org.irods.jargon.ticket.Ticket)1 TicketAdminService (org.irods.jargon.ticket.TicketAdminService)1