@Override
  protected String save(UrnObject urnObject) {
    ByteArrayInputStream stream = new ByteArrayInputStream(urnObject.bytes);

    DBObject metadata = new BasicDBObject();
    metadata.put(FIELD_STORED, urnObject.stored);

    if (AssertUtils.isNotEmpty(urnObject.name)) {
      metadata.put(FIELD_NAME, urnObject.name);
    }
    if (AssertUtils.isNotEmpty(urnObject.name)) {
      metadata.put(FIELD_MIME, urnObject.mime);
    }
    if (urnObject.expiry > 0) {
      metadata.put(FIELD_EXPIRY, urnObject.expiry);
    }

    GridFSFile file = this.template.store(stream, urnObject.key, urnObject.mime, metadata);
    if (file == null) {
      return null;
    }

    return file.getFilename();
  }
Пример #2
0
  @PUT
  @Path("{queue}")
  @Produces(value = {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  public LineUpQueue create(
      @PathParam("queue") String queueName,
      @DefaultValue("") @QueryParam("queueType") String queueType) {
    try {
      if (AssertUtils.isEmpty(queueType)) {
        return this.queueService.createQueue(queueName);
      }

      // try and decipher the type
      QueueType type = QueueType.fromString(queueType);
      if (type == null) {
        throw new WebApplicationException(HttpStatusCode.BAD_REQUEST);
      }

      return this.queueService.createQueue(queueName, QueueOptions.getOptions(type));
    } catch (QueueAlreadyExistsException e) {
      throw new WebApplicationException(HttpStatusCode.CONFLICT);
    }
  }