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

org.apache.streampipes.rest.impl.datalake.DataLakeNoUserManagementV3 Maven / Gradle / Ivy

There is a newer version: 0.95.1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.apache.streampipes.rest.impl.datalake;

import org.apache.streampipes.model.datalake.DataLakeMeasure;
import org.apache.streampipes.model.schema.EventProperty;
import org.apache.streampipes.model.schema.EventPropertyList;
import org.apache.streampipes.model.schema.EventPropertyNested;
import org.apache.streampipes.model.schema.EventPropertyPrimitive;
import org.apache.streampipes.model.schema.EventSchema;
import org.apache.streampipes.rest.impl.AbstractRestInterface;

import java.util.Collections;
import java.util.List;
import java.util.Optional;


public class DataLakeNoUserManagementV3 extends AbstractRestInterface {

  public boolean addDataLake(String measure, EventSchema eventSchema) {
    List dataLakeMeasureList = getDataLakeStorage().getAllDataLakeMeasures();
    Optional optional = dataLakeMeasureList.stream().filter(entry -> entry.getMeasureName().equals(measure)).findFirst();

    if (optional.isPresent()) {
      if (!compareEventProperties(optional.get().getEventSchema().getEventProperties(), eventSchema.getEventProperties())) {
        return false;
      }
    } else {
      getDataLakeStorage().storeDataLakeMeasure(new DataLakeMeasure(measure, eventSchema));
    }
    return true;
  }

  private boolean compareEventProperties(List prop1, List prop2) {
    if (prop1.size() != prop2.size()) {
      return false;
    }

    return prop1.stream().allMatch(prop -> {

      for (EventProperty property : prop2) {
        if (prop.getRuntimeName().equals(property.getRuntimeName())) {

          //primitive
          if (prop instanceof EventPropertyPrimitive && property instanceof EventPropertyPrimitive) {
            if (((EventPropertyPrimitive) prop)
                    .getRuntimeType()
                    .equals(((EventPropertyPrimitive) property).getRuntimeType())) {
              return true;
            }

            //list
          } else if (prop instanceof EventPropertyList && property instanceof EventPropertyList) {
            return compareEventProperties(Collections.singletonList(((EventPropertyList) prop).getEventProperty()),
                    Collections.singletonList(((EventPropertyList) property).getEventProperty()));

            //nested
          } else if (prop instanceof EventPropertyNested && property instanceof EventPropertyNested) {
            return compareEventProperties(((EventPropertyNested) prop).getEventProperties(),
                    ((EventPropertyNested) property).getEventProperties());
          }
        }
      }
      return false;

    });
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy