protected Ticket createTicketForUpdate(Ticket ticket, int operationCode) throws Exception {
   Ticket newTicket = (Ticket) ticket.clone();
   switch (operationCode) {
     case TicketOperation.OPERATIONS_TAKEINCHARGE:
       newTicket.setStatus(Ticket.STATES_ASSIGNED);
       newTicket.setWttOperator(this.getCurrentUser().getUsername());
       break;
     case TicketOperation.OPERATIONS_SETASSIGNABLE:
       newTicket.setStatus(Ticket.STATES_ASSIGNABLE);
       newTicket.setWttOperator(null);
       newTicket.setWttRole(this.getRoleName());
       break;
     case TicketOperation.OPERATIONS_UPDATE:
       if (newTicket.getStatus() == Ticket.STATES_OPENED) {
         newTicket.setStatus(Ticket.STATES_WORKING);
       }
       int priority = this.getPriority() != null ? this.getPriority().intValue() : 0;
       newTicket.setPriority(priority);
       int interventionType =
           this.getInterventionType() != null ? this.getInterventionType().intValue() : 0;
       newTicket.setOpInterventionType(interventionType);
       break;
     case TicketOperation.OPERATIONS_CLOSE:
       newTicket.setStatus(Ticket.STATES_CLOSED);
       newTicket.setClosingDate(new Date());
       if (this.getResolved() != null) {
         newTicket.setResolved(this.getResolved().booleanValue());
       }
       newTicket.setWttOperator(null);
       break;
     case TicketOperation.OPERATIONS_ANSWER:
       if (newTicket.getStatus() == Ticket.STATES_OPENED) {
         newTicket.setStatus(Ticket.STATES_WORKING);
       }
       break;
     case TicketOperation.OPERATIONS_RELEASE:
       newTicket.setStatus(Ticket.STATES_WORKING);
       newTicket.setClosingDate(null);
       newTicket.setResolved(false);
       newTicket.setWttOperator(null);
       break;
   }
   if (this.getPriority() != null) {
     newTicket.setPriority(this.getPriority().intValue());
   }
   return newTicket;
 }
 @Override
 protected boolean isAccessAllowed(Ticket ticket) {
   UserDetails currentUser = this.getCurrentUser();
   boolean allowed = false;
   int status = ticket.getStatus();
   if (this.getAuthorizationManager()
           .isAuthOnPermission(currentUser, JpWttSystemConstants.WTT_ADMIN_PERMISSION)
       || (Ticket.STATES_ASSIGNABLE == status && this.userHasRole(ticket.getWttRole()))
       || Ticket.STATES_ASSIGNED == status
           && currentUser.getUsername().equals(ticket.getWttOperator())) {
     allowed = true;
   }
   return allowed;
 }
 public boolean isOperationAllowed(Ticket ticket, int operationCode) {
   boolean allowed = false;
   int status = ticket.getStatus();
   String operator = ticket.getWttOperator();
   UserDetails currentUser = this.getCurrentUser();
   boolean isAdmin =
       this.getAuthorizationManager()
           .isAuthOnPermission(currentUser, JpWttSystemConstants.WTT_ADMIN_PERMISSION);
   switch (operationCode) {
     case TicketOperation.OPERATIONS_SETASSIGNABLE:
       if (isAdmin && (Ticket.STATES_OPENED == status || Ticket.STATES_WORKING == status)) {
         allowed = true;
       }
       break;
     case TicketOperation.OPERATIONS_TAKEINCHARGE:
       if ((isAdmin && (Ticket.STATES_OPENED == status || Ticket.STATES_WORKING == status))
           || (Ticket.STATES_ASSIGNABLE == status && this.userHasRole(ticket.getWttRole()))) {
         allowed = true;
       }
       break;
     case TicketOperation.OPERATIONS_ANSWER:
     case TicketOperation.OPERATIONS_UPDATE:
     case TicketOperation.OPERATIONS_CLOSE:
       if (Ticket.STATES_ASSIGNED == status && currentUser.getUsername().equals(operator)) {
         allowed = true;
       }
       break;
     case TicketOperation.OPERATIONS_RELEASE:
       if ((isAdmin && (Ticket.STATES_ASSIGNABLE == status || Ticket.STATES_ASSIGNED == status))
           || (Ticket.STATES_ASSIGNED == status && currentUser.getUsername().equals(operator))) {
         allowed = true;
       }
       break;
   }
   return allowed;
 }