Package com.getperka.flatpack

Examples of com.getperka.flatpack.HasUuid


  }

  @Override
  public T readNotNull(JsonElement element, DeserializationContext context) {
    UUID uuid = UUID.fromString(element.getAsString());
    HasUuid entity = context.getEntity(uuid);
    /*
     * If the UUID is a reference to an entity that isn't in the data section, delegate to the
     * allocate() method. The entity will either be provided by an EntityResolver or a blank entity
     * will be created if possible.
     */
    if (entity == null) {
      entity = allocate(uuid, element, context, true);
    }
    try {
      return clazz.cast(entity);
    } catch (ClassCastException e) {
      throw new ClassCastException("Cannot cast a " + entity.getClass().getName()
        + " to a " + clazz.getName() + ". Duplicate UUID in data payload?");
    }
  }
View Full Code Here


  @Override
  public Void call() throws Exception {
    Class<?> type = toSet.getGetter().getReturnType();
    if (Collection.class.isAssignableFrom(type)) {
      HasUuid entity = (HasUuid) target;
      Collection<Object> collection = null;

      /*
       * Update implied collections in-place. If the incoming payload had an explicit value for the
       * collection property, it will have been reset to a new collection instance already.
View Full Code Here

        String value = primitive.getAsString();

        // Interpret UUIDs as entity references
        if (UUID_PATTERN.matcher(value).matches()) {
          UUID uuid = UUID.fromString(value);
          HasUuid entity = context.getEntity(uuid);
          if (entity != null) {
            return entity;
          }
        }
View Full Code Here

           * Embedded objects are never referred to by uuid in the payload, so an instance will need
           * to be allocated before reading in the properties.
           */
          @SuppressWarnings("unchecked")
          EntityCodex<HasUuid> codex = (EntityCodex<HasUuid>) prop.getCodex();
          HasUuid embedded = codex.allocateEmbedded(payload, context);
          value = ctx.walkImmutable(codex).accept(this, embedded);
        } else {

          @SuppressWarnings("unchecked")
          Codex<Object> codex = (Codex<Object>) prop.getCodex();

          // merchant would become merchantUuid
          String payloadPropertyName = simplePropertyName + codex.getPropertySuffix();

          // Ignore undefined property values, while allowing explicit nullification
          if (!payload.has(payloadPropertyName)) {
            return;
          }

          value = codex.read(payload.get(payloadPropertyName), context);
        }

        if (value == null && prop.getSetter().getParameterTypes()[0].isPrimitive()) {
          // Don't try to pass a null to a primitive setter
          return;
        }

        HasUuid entity = stack.peek().entity;

        // Verify the new value may be set
        if (!checkAccess(entity, prop, value, context)) {
          return;
        }
View Full Code Here

  }

  private boolean checkAccess(Object object, Property property, Object value,
      DeserializationContext ctx) throws Exception {
    if (object instanceof HasUuid) {
      HasUuid entity = (HasUuid) object;
      Principal principal = ctx.getPrincipal();
      // Verify the new value may be set
      SecurityTarget target = SecurityTarget.of(entity, property);

      switch (context.getEntitySource(entity)) {
View Full Code Here

    assertEquals("Hello World!", codex.read(new JsonPrimitive("Hello World!"), ctx));

    UUID uuid = UUID.randomUUID();
    assertEquals(uuid.toString(), codex.read(new JsonPrimitive(uuid.toString()), ctx));

    HasUuid entity = new BaseHasUuid();
    ctx.putEntity(uuid, entity, EntitySource.RESOLVED);
    assertSame(entity, codex.read(new JsonPrimitive(uuid.toString()), ctx));
  }
View Full Code Here

        }
        continue;
      }

      // Entity-relative
      final HasUuid entity = target.getEntity();
      if (entity != null) {
        final AtomicBoolean found = new AtomicBoolean();
        for (PropertyPath path : group.getPaths()) {
          path.evaluate(entity, new Receiver() {
            @Override
View Full Code Here

TOP

Related Classes of com.getperka.flatpack.HasUuid

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.