Exemple #1
0
 private Response lookupResponse(Entity entity, Lookup lookup, Locale locale) {
   if (lookup.isSingleObjectReturn()) {
     return new ResponseWithSchema(
         msg(locale, RESPONSE_SINGLE_DESC_KEY, entity.getName()),
         definitionWithMetadataPath(entity.getClassName()));
   } else {
     return new ResponseWithSchema(
         msg(locale, RESPONSE_LIST_DESC_KEY, entity.getName()),
         definitionWithMetadataPath(entity.getClassName()));
   }
 }
Exemple #2
0
  private static Entity findEntityByName(String name, List<Entity> allEntities) {
    for (Entity entity : allEntities) {
      if (entity.getClassName().equals(name)) {
        return entity;
      }
    }

    return null;
  }
Exemple #3
0
  private static void assertRelationshipIsHistoryCompatible(
      Field field, RelationshipHolder holder, List<Entity> allEntities) {
    Entity relatedEntity = findEntityByName(holder.getRelatedClass(), allEntities);

    if (!hasCorrectTrackingSettings(field, relatedEntity, holder)) {
      String relatedClassName = relatedEntity == null ? "null" : relatedEntity.getClassName();
      throw new InvalidEntitySettingsException(field.getEntity().getClassName(), relatedClassName);
    }
  }
Exemple #4
0
  private void addDefinitions(SwaggerModel swaggerModel, Entity entity) {
    RestOptions restOptions = restOptionsOrDefault(entity);

    if (restOptions.supportsAnyOperation() || !entity.getLookupsExposedByRest().isEmpty()) {
      // all fields, including generated ones
      swaggerModel.addDefinition(entity.getClassName(), definition(entity, true, true));
      swaggerModel.addDefinition(
          entity.getClassName() + "-WithMetadata", definitionWithMetadata(entity));
    }
    if (restOptions.isAllowCreate()) {
      // no auto-generated fields
      swaggerModel.addDefinition(
          definitionNewName(entity.getClassName()), definition(entity, false, false));
    }
    if (restOptions.isAllowUpdate()) {
      // no auto-generated fields, except ID
      swaggerModel.addDefinition(
          definitionUpdateName(entity.getClassName()), definition(entity, false, true));
    }
  }
 private ImportExportBlueprint sortBlueprintRecords(ImportExportBlueprint blueprint) {
   List<Entity> entities = new ArrayList<>(blueprint.size());
   for (ImportExportBlueprint.Record record : blueprint) {
     entities.add(allEntities.retrieveByClassName(record.getEntityName()));
   }
   RelationshipSorter relationshipSorter = new RelationshipSorter();
   relationshipSorter.sort(entities);
   ImportExportBlueprint sortedBlueprint = new ImportExportBlueprint();
   for (Entity entity : entities) {
     String entityName = entity.getClassName();
     sortedBlueprint.includeEntitySchema(entityName, blueprint.isIncludeEntitySchema(entityName));
     sortedBlueprint.includeEntityData(entityName, blueprint.isIncludeEntityData(entityName));
   }
   return sortedBlueprint;
 }
Exemple #6
0
  private PathEntry deletePathEntry(Entity entity, Locale locale) {
    final PathEntry pathEntry = new PathEntry();

    final String entityName = entity.getName();

    pathEntry.setDescription(msg(locale, DELETE_DESC_KEY, entityName));
    pathEntry.setOperationId(msg(locale, DELETE_ID_KEY, entityName));
    pathEntry.setProduces(json());
    pathEntry.addTag(entity.getClassName());

    pathEntry.addParameter(deleteIdPathParameter(locale));

    addCommonResponses(pathEntry, locale);
    pathEntry.addResponse(HttpStatus.OK, deleteResponse(entity, locale));

    return pathEntry;
  }
Exemple #7
0
  private PathEntry putPathEntry(Entity entity, Locale locale) {
    final PathEntry pathEntry = new PathEntry();

    final String entityName = entity.getName();

    pathEntry.setDescription(msg(locale, UPDATE_DESC_KEY, entityName));
    pathEntry.setOperationId(msg(locale, UPDATE_ID_KEY, entityName));
    pathEntry.setProduces(json());
    pathEntry.addTag(entity.getClassName());

    pathEntry.addParameter(updateEntityParameter(entity, locale));

    addCommonResponses(pathEntry, locale);
    pathEntry.addResponse(HttpStatus.OK, updatedItemResponse(entity, locale));
    pathEntry.addResponse(HttpStatus.NOT_FOUND, notFoundResponse(entity, locale));

    return pathEntry;
  }
Exemple #8
0
  private PathEntry readPathEntry(Entity entity, Locale locale) {
    final PathEntry pathEntry = new PathEntry();

    final String entityName = entity.getName();

    pathEntry.setDescription(msg(locale, READ_DESC_KEY, entityName));
    pathEntry.setOperationId(msg(locale, READ_ID_KEY, entityName));
    pathEntry.setProduces(json());
    pathEntry.addTag(entity.getClassName());

    pathEntry.setParameters(queryParamsParameters(entity.getFieldsExposedByRest(), locale));
    pathEntry.addParameter(idQueryParameter(locale));

    pathEntry.addResponse(HttpStatus.OK, readResponse(entity, locale));
    addCommonResponses(pathEntry, locale);

    return pathEntry;
  }
Exemple #9
0
  private PathEntry lookupPathEntry(Entity entity, Lookup lookup, Locale locale) {
    final PathEntry pathEntry = new PathEntry();

    pathEntry.setDescription(msg(locale, LOOKUP_DESC_KEY, lookup.getLookupName()));
    pathEntry.setOperationId(lookup.getMethodName());
    pathEntry.setProduces(json());
    pathEntry.addTag(entity.getClassName());

    pathEntry.setParameters(lookupParameters(entity, lookup, locale));

    pathEntry.addResponse(HttpStatus.OK, lookupResponse(entity, lookup, locale));
    addCommonResponses(pathEntry, locale);

    if (lookup.isSingleObjectReturn()) {
      pathEntry.addResponse(HttpStatus.NOT_FOUND, lookup404Response(entity, locale));
    }

    return pathEntry;
  }
Exemple #10
0
  private Definition definitionWithMetadata(Entity entity) {
    final Definition definition = new Definition();

    Property metadata = new Property();
    metadata.setRef(definitionPath("Metadata"));
    Property data = new Property(ARRAY_TYPE);
    data.setRef(definitionPath(entity.getClassName()));

    final Map<String, Property> properties = new LinkedHashMap<>();
    properties.put("metadata", metadata);
    properties.put("data", data);

    final List<String> required = new ArrayList<>();
    required.add("metadata");
    required.add("data");

    definition.setProperties(properties);
    definition.setRequired(required);

    return definition;
  }
Exemple #11
0
 private Response updatedItemResponse(Entity entity, Locale locale) {
   return new ResponseWithSchema(
       msg(locale, RESPONSE_UPDATED_DESC_KEY, entity.getName()),
       definitionPath(entity.getClassName()));
 }
Exemple #12
0
 private Response readResponse(Entity entity, Locale locale) {
   return new ResponseWithSchema(
       msg(locale, RESPONSE_LIST_DESC_KEY, entity.getName()),
       definitionWithMetadataPath(entity.getClassName()));
 }
Exemple #13
0
 private Parameter updateEntityParameter(Entity entity, Locale locale) {
   return bodyParameter(
       entity.getName(),
       msg(locale, UPDATE_BODY_DESC_KEY, entity.getName()),
       definitionUpdatePath(entity.getClassName()));
 }
Exemple #14
0
 private Parameter newEntityParameter(Entity entity, Locale locale) {
   return bodyParameter(
       entity.getName(),
       msg(locale, CREATE_BODY_DESC_KEY, entity.getName()),
       definitionNewPath(entity.getClassName()));
 }