Search in sources :

Example 1 with DataGridTicket

use of com.emc.metalnx.core.domain.entity.DataGridTicket in project metalnx-web by irods-contrib.

the class TicketServiceImpl method modify.

@Override
public DataGridTicket modify(DataGridTicket t) throws DataGridConnectionRefusedException, DataGridTicketException {
    logger.info("Modify ticket");
    if (t == null) {
        logger.error("Null ticket provided.");
        throw new DataGridTicketException("Null ticket instance");
    }
    if (t.getTicketString().isEmpty()) {
        logger.error("Ticket with empty string provided.");
        throw new DataGridTicketException("Ticket string missing");
    }
    String ticketString = t.getTicketString();
    DataGridTicket dgTicket;
    try {
        updateHostRestrictions(t);
        updateUserRestrictions(t);
        updateGroupRestrictions(t);
        TicketAdminService tas = irodsServices.getTicketAdminService();
        Ticket ticketUpdated = tas.compareGivenTicketToActualAndUpdateAsNeeded(convertDataGridTicketToTicket(t));
        dgTicket = convertTicketToDataGridTicket(ticketUpdated);
        dgTicket.setHosts(tas.listAllHostRestrictionsForSpecifiedTicket(ticketString, OFFSET));
        dgTicket.setUsers(tas.listAllUserRestrictionsForSpecifiedTicket(ticketString, OFFSET));
        dgTicket.setGroups(tas.listAllGroupRestrictionsForSpecifiedTicket(ticketString, OFFSET));
    } catch (JargonException e) {
        logger.error("Could not modify ticket");
        throw new DataGridTicketException(e.getMessage());
    }
    return dgTicket;
}
Also used : DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) Ticket(org.irods.jargon.ticket.Ticket) JargonException(org.irods.jargon.core.exception.JargonException) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) DataGridTicketException(com.emc.metalnx.core.domain.exceptions.DataGridTicketException) TicketAdminService(org.irods.jargon.ticket.TicketAdminService)

Example 2 with DataGridTicket

use of com.emc.metalnx.core.domain.entity.DataGridTicket 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 3 with DataGridTicket

use of com.emc.metalnx.core.domain.entity.DataGridTicket in project metalnx-web by irods-contrib.

the class TicketServiceImpl method convertTicketToDataGridTicket.

private DataGridTicket convertTicketToDataGridTicket(Ticket t) {
    DataGridTicket dgTicket = new DataGridTicket();
    dgTicket.setTicketString(t.getTicketString());
    dgTicket.setOwner(t.getOwnerName());
    dgTicket.setPath(t.getIrodsAbsolutePath());
    dgTicket.setTicketString(t.getTicketString());
    dgTicket.setExpirationDate(t.getExpireTime());
    dgTicket.setUsesLimit(t.getUsesLimit());
    dgTicket.setUsesCount(t.getUsesCount());
    dgTicket.setWriteByteLimit(t.getWriteByteLimit());
    dgTicket.setWriteByteCount(t.getWriteByteCount());
    dgTicket.setWriteFileLimit(t.getWriteFileLimit());
    dgTicket.setWriteFileCount(t.getWriteFileCount());
    DataGridTicket.TicketType dgTicketType;
    if (t.getType() == TicketCreateModeEnum.READ) {
        dgTicketType = DataGridTicket.TicketType.READ;
    } else if (t.getType() == TicketCreateModeEnum.WRITE) {
        dgTicketType = DataGridTicket.TicketType.WRITE;
    } else {
        dgTicketType = DataGridTicket.TicketType.UNKNOWN;
    }
    dgTicket.setType(dgTicketType);
    if (t.getObjectType() == Ticket.TicketObjectType.COLLECTION)
        dgTicket.setIsCollection(true);
    return dgTicket;
}
Also used : DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket)

Example 4 with DataGridTicket

use of com.emc.metalnx.core.domain.entity.DataGridTicket in project metalnx-web by irods-contrib.

the class HostInfo method findAll.

/**
 * Finds all tickets in the grid.
 *
 * @return List of tickets in JSON
 * @throws DataGridConnectionRefusedException
 *             if Metalnx cannot connect to the grid
 * @throws UnsupportedDataGridFeatureException
 */
@RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String findAll() throws DataGridConnectionRefusedException, JsonProcessingException, UnsupportedDataGridFeatureException {
    logger.info("Find all tickets");
    if (!configService.getGlobalConfig().isTicketsEnabled()) {
        logger.error("tickets are not enabled");
        throw new UnsupportedDataGridFeatureException("tickets disabled");
    }
    List<DataGridTicket> tickets = ticketService.findAll();
    Map<String, Object> ticketsAsJSON = new HashMap<>();
    ticketsAsJSON.put("data", tickets);
    return new ObjectMapper().writeValueAsString(ticketsAsJSON);
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) HashMap(java.util.HashMap) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with DataGridTicket

use of com.emc.metalnx.core.domain.entity.DataGridTicket in project metalnx-web by irods-contrib.

the class HostInfo method find.

/**
 * Finds a specific ticket in the grid by its id or string
 *
 * @param ticketId
 *            ticket id or string
 * @return Ticket as JSON
 * @throws DataGridConnectionRefusedException
 *             if Metalnx cannot connect to the grid
 * @throws UnsupportedDataGridFeatureException
 */
@RequestMapping(value = "/{ticketid}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<DataGridTicket> find(@PathVariable("ticketid") final String ticketId) throws DataGridConnectionRefusedException, DataGridTicketNotFoundException, UnsupportedDataGridFeatureException {
    logger.info("Find ticket by its ID or String");
    if (!configService.getGlobalConfig().isTicketsEnabled()) {
        logger.error("tickets are not enabled");
        throw new UnsupportedDataGridFeatureException("tickets disabled");
    }
    DataGridTicket dgTicket = ticketService.find(ticketId);
    return new ResponseEntity<>(dgTicket, HttpStatus.OK);
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) ResponseEntity(org.springframework.http.ResponseEntity) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DataGridTicket (com.emc.metalnx.core.domain.entity.DataGridTicket)25 Test (org.junit.Test)10 Before (org.junit.Before)7 Ticket (org.irods.jargon.ticket.Ticket)4 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)3 JargonException (org.irods.jargon.core.exception.JargonException)3 TicketAdminService (org.irods.jargon.ticket.TicketAdminService)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Date (java.util.Date)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 DataGridTicketException (com.emc.metalnx.core.domain.exceptions.DataGridTicketException)1 DataGridTicketNotFoundException (com.emc.metalnx.core.domain.exceptions.DataGridTicketNotFoundException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DataNotFoundException (org.irods.jargon.core.exception.DataNotFoundException)1 TicketCreateModeEnum (org.irods.jargon.ticket.packinstr.TicketCreateModeEnum)1 ResponseEntity (org.springframework.http.ResponseEntity)1