예제 #1
0
 /** {@inheritDoc} */
 public Map<String, Property<?>> readAllProperties() {
   Response cRes = getStore().request(MediaType.APPLICATION_JSON_TYPE).get();
   if (Status.OK.getStatusCode() != cRes.getStatus()) {
     throw new PropertyAccessException(
         "Cannot read properties, an HTTP error " + cRes.getStatus() + " occured.");
   }
   String resEntity = cRes.readEntity(String.class);
   Property<?>[] pArray = PropertyJsonParser.parsePropertyArray(resEntity);
   Map<String, Property<?>> properties = new HashMap<String, Property<?>>();
   for (Property<?> pName : pArray) {
     properties.put(pName.getName(), pName);
   }
   return properties;
 }
예제 #2
0
  /** {@inheritDoc} */
  public <T> void createProperty(Property<T> value) {
    Util.assertNotNull(value);
    Util.assertHasLength(value.getName());
    if (existProperty(value.getName())) {
      throw new PropertyAlreadyExistException("Property already exist");
    }
    // Now can process upsert through PUT HTTP method
    Response cRes =
        getStore()
            .path(value.getName()) //
            .request(MediaType.APPLICATION_JSON)
            .put(Entity.entity(new PropertyApiBean(value), MediaType.APPLICATION_JSON));

    // Check response code CREATED or raised error
    if (Status.CREATED.getStatusCode() != cRes.getStatus()) {
      throw new FeatureAccessException(
          "Cannot create properties, an HTTP error " + cRes.getStatus() + " occured.");
    }
  }