All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.stargate.sgv2.graphql.schema.graphqlfirst.fetchers.admin.DeploySchemaResponseDto Maven / Gradle / Ivy

There is a newer version: 2.0.0-ALPHA-17
Show newest version
package io.stargate.sgv2.graphql.schema.graphqlfirst.fetchers.admin;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import graphql.GraphqlErrorHelper;
import graphql.schema.DataFetchingEnvironment;
import io.stargate.sgv2.graphql.schema.graphqlfirst.migration.MigrationQuery;
import io.stargate.sgv2.graphql.schema.graphqlfirst.processor.ProcessingLogType;
import io.stargate.sgv2.graphql.schema.graphqlfirst.processor.ProcessingMessage;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class DeploySchemaResponseDto {

  private UUID version;
  private List> logs;
  private List cqlChanges;

  public void setVersion(UUID version) {
    this.version = version;
  }

  public UUID getVersion() {
    return version;
  }

  public void setLogs(List> logs) {
    this.logs = logs;
  }

  public List> getLogs(DataFetchingEnvironment environment) {
    Stream> stream = logs.stream();
    ProcessingLogType category = environment.getArgument("category");
    if (category != null) {
      stream = stream.filter(m -> m.getErrorType() == category);
    }
    return stream.map(this::formatMessage).collect(Collectors.toList());
  }

  public void setCqlChanges(List cqlChanges) {
    this.cqlChanges = cqlChanges;
  }

  public List getCqlChanges() {
    return cqlChanges.isEmpty()
        ? ImmutableList.of("No changes, the CQL schema is up to date")
        : cqlChanges.stream().map(MigrationQuery::getDescription).collect(Collectors.toList());
  }

  private Map formatMessage(ProcessingMessage message) {
    return ImmutableMap.of(
        "message",
        message.getMessage(),
        "category",
        message.getErrorType(),
        "locations",
        message.getLocations().stream()
            .map(GraphqlErrorHelper::location)
            .collect(Collectors.toList()));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy