Beispiel #1
0
  protected void setUp() throws Exception {

    if (mn == null) {
      mn = new Main("jetty");
      mn.run(new String[] {"jetty"});
    }

    QueryService service = new QueryServiceLocator();
    query = service.getQuery(new URL(query_url));
    sessionId = query.connect("admin", "");
    AdminService aservice = new AdminServiceLocator();
    admin = aservice.getAdmin(new URL(admin_url));
  }
Beispiel #2
0
 // Если тэга с таким именем не было - просто создается, если был, но был удален без очистки линков
 // - восстанавливается
 // Если имя тэга уникально, при попытке добавления такого-же будет ошибка
 public void create(String name, Long pkId) {
   if (adminService.tarifIsNotExpired(pkId)) {
     boolean unique = true;
     boolean deleted = false;
     Tag existingTag = getTagByNameAndPkId(name, pkId);
     Tag deletedTag = getDeletedTagByNameAndPkId(name, pkId);
     if (existingTag != null) {
       unique = false;
       if (deletedTag != null) {
         deleted = true;
       }
     }
     if (unique) {
       Tag tag = new Tag();
       tag.setCabinet(pkDao.find(pkId));
       tag.setName(name);
       if (validate(tag)) {
         tagDao.save(tag);
       }
     } else {
       if (deleted) {
         deletedTag.setDeleteDate(null);
         if (validate(deletedTag)) {
           tagDao.update(deletedTag);
         }
       } else {
         addError("Такой тэг уже есть");
       }
     }
   } else {
     addError("Не удалось добваить тэг в связи с ограничениями тарифа");
   }
 }
  @Override
  @RequestMapping(value = "/admin/suspendAccount", method = RequestMethod.POST)
  public ResponseEntity suspendAccount(
      @RequestBody AccountSuspensionInfo suspendInfo,
      @RequestHeader(value = "token") String token) {
    String actionName = "AdminControllerImpl.suspendAccount";

    try {
      if (!sessionService.isSessionActive(token)) {
        return new ResponseEntity<>(HttpStatus.FORBIDDEN);
      }

      String userRoleForToken = sessionService.getUserRoleByToken(token);
      String usernameForToken = sessionService.getUsernameByToken(token);

      try {
        if (permissionService.isOperationAvailable(actionName, userRoleForToken)) {
          adminService.suspendAccount(suspendInfo);

          auditService.addEvent(
              new AuditItem(
                  usernameForToken,
                  actionName,
                  suspendInfo.toString(),
                  Constants.ADMIN_SUSPEND,
                  true));
          return new ResponseEntity<>(HttpStatus.OK);
        } else {
          auditService.addEvent(
              new AuditItem(
                  usernameForToken,
                  actionName,
                  suspendInfo.toString(),
                  Constants.NO_PERMISSION,
                  false));
          return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
        }
      } catch (ServiceException serviceException) {
        auditService.addEvent(
            new AuditItem(
                usernameForToken,
                actionName,
                suspendInfo.toString(),
                serviceException.getMessage(),
                false));
        return new ResponseEntity<>(serviceException.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY);

      } catch (NotFoundException notFoundException) {
        auditService.addEvent(
            new AuditItem(
                usernameForToken,
                actionName,
                suspendInfo.toString(),
                notFoundException.getMessage(),
                false));
        return new ResponseEntity<>(notFoundException.getMessage(), HttpStatus.NOT_FOUND);
      }
    } catch (ServiceException serviceException) {
      return new ResponseEntity<>(serviceException.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY);
    }
  }