Пример #1
0
 @Test
 public void getMe() {
   final Data<User> me = pinterest.userOperations().getMe("id,image(small)");
   System.out.println(me.getData().getBio());
   System.out.println(me.getData().getId());
   System.out.println(me.getData().getImage().getSmall());
   System.out.println(me);
 }
Пример #2
0
  public static void main(String[] args) {
    int op = 0, d, m, a;
    Scanner in = new Scanner(System.in);
    Data data = new Data();

    while (op != 5) {
      System.out.println("\n\nData atual: " + data.getData());
      System.out.println("Escolha uma opção: ");
      System.out.println(" 1. Definir nova data;\n 2. Trocar o dia;");
      System.out.println(" 3. Trocar o mês;\n 4. Trocar o ano;");
      System.out.println(" 5. Sair.");
      System.out.print("Opção: ");
      op = in.nextInt();

      switch (op) {
        case 1:
          System.out.print("Entre com o dia: ");
          d = in.nextInt();
          System.out.print("Entre com o mes: ");
          m = in.nextInt();
          System.out.print("Entre com o ano: ");
          a = in.nextInt();

          data.setData(d, m, a);

          break;
        case 2:
          System.out.print("Entre com o novo dia: ");
          d = in.nextInt();
          data.setData(d, data.getMes(), data.getAno());

          break;
        case 3:
          System.out.print("Entre com o novo mês: ");
          m = in.nextInt();
          data.setData(data.getDia(), m, data.getAno());

          break;
        case 4:
          System.out.print("Entre com o novo ano: ");
          a = in.nextInt();
          data.setData(data.getDia(), data.getMes(), a);

          break;
        case 5:
          System.out.println("Saindo...");
          break;
        default:
          System.out.println("Entre com um número entre 1 e 5!");
          break;
      }
    }
  }
Пример #3
0
  public static void initMajorListWithData() {

    System.out.println("preparing majorList");
    for (String[] singleData : Data.getData(LEVEL)) {
      MajorForCollection major = new MajorForCollection();
      major.setLevel(LEVEL);
      major.setApplicationFee(singleData[0]);
      major.setUrl(singleData[1]);
      majorList.add(major);
    }
    System.out.println("majorList prepared");
    System.out.println("majorList size: " + majorList.size());
  }
Пример #4
0
  public static void main(String[] args) {

    Data.DataDEG data = new Data.DataDEG();

    Data.getData(data);
    System.out.println("nVertexes: " + data.nVertexes);
    System.out.println("nEdges: " + data.nEdges);

    //		for (Edge edge : data.edges) {
    //			System.out.println("edge: " + edge);
    //		}

    int[] dataOut = Algorithms.degreeArray(data);
    System.out.println(Arrays.toString(dataOut));
  }
  /** {@inheritDoc} */
  @Override
  protected DataExecutionResponse run(
      DataBuilderContext dataBuilderContext,
      DataFlowInstance dataFlowInstance,
      DataDelta dataDelta,
      DataFlow dataFlow,
      DataBuilderFactory builderFactory)
      throws DataBuilderFrameworkException, DataValidationException {
    CompletionService<DataContainer> completionExecutor =
        new ExecutorCompletionService<DataContainer>(executorService);
    ExecutionGraph executionGraph = dataFlow.getExecutionGraph();
    DataSet dataSet =
        dataFlowInstance.getDataSet().accessor().copy(); // Create own copy to work with
    DataSetAccessor dataSetAccessor = DataSet.accessor(dataSet);
    dataSetAccessor.merge(dataDelta);
    Map<String, Data> responseData = Maps.newTreeMap();
    Set<String> activeDataSet = Sets.newHashSet();

    for (Data data : dataDelta.getDelta()) {
      activeDataSet.add(data.getData());
    }
    List<List<DataBuilderMeta>> dependencyHierarchy = executionGraph.getDependencyHierarchy();
    Set<String> newlyGeneratedData = Sets.newHashSet();
    Set<DataBuilderMeta> processedBuilders =
        Collections.synchronizedSet(Sets.<DataBuilderMeta>newHashSet());
    while (true) {
      for (List<DataBuilderMeta> levelBuilders : dependencyHierarchy) {
        List<Future<DataContainer>> dataFutures = Lists.newArrayList();
        for (DataBuilderMeta builderMeta : levelBuilders) {
          if (processedBuilders.contains(builderMeta)) {
            continue;
          }
          // If there is an intersection, means some of it's inputs have changed. Reevaluate
          if (Sets.intersection(builderMeta.getConsumes(), activeDataSet).isEmpty()) {
            continue;
          }
          DataBuilder builder = builderFactory.create(builderMeta.getName());
          if (!dataSetAccessor.checkForData(builder.getDataBuilderMeta().getConsumes())) {
            break; // No need to run others, list is topo sorted
          }
          BuilderRunner builderRunner =
              new BuilderRunner(
                  dataBuilderExecutionListener,
                  dataFlowInstance,
                  builderMeta,
                  dataDelta,
                  responseData,
                  builder,
                  dataBuilderContext,
                  processedBuilders,
                  dataSet);
          Future<DataContainer> future = completionExecutor.submit(builderRunner);
          dataFutures.add(future);
        }

        // Now wait for something to complete.
        int listSize = dataFutures.size();
        for (int i = 0; i < listSize; i++) {
          try {
            DataContainer responseContainer = completionExecutor.take().get();
            Data response = responseContainer.getGeneratedData();
            if (responseContainer.isHasError()) {
              if (null != responseContainer.getValidationException()) {
                throw responseContainer.getValidationException();
              }

              throw responseContainer.getException();
            }
            if (null != response) {
              dataSetAccessor.merge(response);
              responseData.put(response.getData(), response);
              activeDataSet.add(response.getData());
              if (null != dataFlow.getTransients()
                  && !dataFlow.getTransients().contains(response.getData())) {
                newlyGeneratedData.add(response.getData());
              }
            }
          } catch (InterruptedException e) {
            throw new DataBuilderFrameworkException(
                DataBuilderFrameworkException.ErrorCode.BUILDER_EXECUTION_ERROR,
                "Error while waiting for error ",
                e);
          } catch (ExecutionException e) {
            throw new DataBuilderFrameworkException(
                DataBuilderFrameworkException.ErrorCode.BUILDER_EXECUTION_ERROR,
                "Error while waiting for error ",
                e.getCause());
          }
        }
      }
      if (newlyGeneratedData.contains(dataFlow.getTargetData())) {
        // logger.debug("Finished running this instance of the flow. Exiting.");
        break;
      }
      if (newlyGeneratedData.isEmpty()) {
        // logger.debug("Nothing happened in this loop, exiting..");
        break;
      }
      //            StringBuilder stringBuilder = new StringBuilder();
      //            for(String data : newlyGeneratedData) {
      //                stringBuilder.append(data + ", ");
      //            }
      // logger.info("Newly generated: " + stringBuilder);
      activeDataSet.clear();
      activeDataSet.addAll(newlyGeneratedData);
      newlyGeneratedData.clear();
      if (!dataFlow.isLoopingEnabled()) {
        break;
      }
    }
    DataSet finalDataSet = dataSetAccessor.copy(dataFlow.getTransients());
    dataFlowInstance.setDataSet(finalDataSet);
    return new DataExecutionResponse(responseData);
  }
    @Override
    public DataContainer call() throws Exception {

      for (DataBuilderExecutionListener listener : dataBuilderExecutionListener) {
        try {
          listener.beforeExecute(dataFlowInstance, builderMeta, dataDelta, responseData);
        } catch (Throwable t) {
          logger.error("Error running pre-execution execution listener: ", t);
        }
      }
      try {
        Data response =
            builder.process(
                dataBuilderContext.immutableCopy(
                    dataSet.accessor().getAccesibleDataSetFor(builder)));
        // logger.debug("Ran " + builderMeta.getName());
        procesedBuilders.add(builderMeta);
        for (DataBuilderExecutionListener listener : dataBuilderExecutionListener) {
          try {
            listener.afterExecute(dataFlowInstance, builderMeta, dataDelta, responseData, response);
          } catch (Throwable t) {
            logger.error("Error running post-execution listener: ", t);
          }
        }
        if (null != response) {
          Preconditions.checkArgument(
              response.getData().equalsIgnoreCase(builderMeta.getProduces()),
              String.format(
                  "Builder is supposed to produce %s but produces %s",
                  builderMeta.getProduces(), response.getData()));
          response.setGeneratedBy(builderMeta.getName());
        }
        return new DataContainer(builderMeta, response);
      } catch (DataBuilderException e) {
        logger.error("Error running builder: " + builderMeta.getName());
        for (DataBuilderExecutionListener listener : dataBuilderExecutionListener) {
          try {
            listener.afterException(dataFlowInstance, builderMeta, dataDelta, responseData, e);

          } catch (Throwable error) {
            logger.error("Error running post-execution listener: ", error);
          }
        }
        return new DataContainer(
            builderMeta,
            new DataBuilderFrameworkException(
                DataBuilderFrameworkException.ErrorCode.BUILDER_EXECUTION_ERROR,
                "Error running builder: " + builderMeta.getName(),
                e.getDetails(),
                e));

      } catch (DataValidationException e) {
        logger.error("Validation error in data produced by builder" + builderMeta.getName());
        for (DataBuilderExecutionListener listener : dataBuilderExecutionListener) {
          try {
            listener.afterException(dataFlowInstance, builderMeta, dataDelta, responseData, e);

          } catch (Throwable error) {
            logger.error("Error running post-execution listener: ", error);
          }
        }
        return new DataContainer(
            builderMeta,
            new DataValidationException(
                DataValidationException.ErrorCode.DATA_VALIDATION_EXCEPTION,
                "Error running builder: " + builderMeta.getName(),
                new DataExecutionResponse(responseData),
                e.getDetails(),
                e));

      } catch (Throwable t) {
        logger.error("Error running builder: " + builderMeta.getName());
        for (DataBuilderExecutionListener listener : dataBuilderExecutionListener) {
          try {
            listener.afterException(dataFlowInstance, builderMeta, dataDelta, responseData, t);

          } catch (Throwable error) {
            logger.error("Error running post-execution listener: ", error);
          }
        }
        Map<String, Object> objectMap = new HashMap<String, Object>();
        objectMap.put("MESSAGE", t.getMessage());
        return new DataContainer(
            builderMeta,
            new DataBuilderFrameworkException(
                DataBuilderFrameworkException.ErrorCode.BUILDER_EXECUTION_ERROR,
                "Error running builder: " + builderMeta.getName() + t.getMessage(),
                objectMap,
                t));
      }
    }