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

com.arextest.storage.service.config.AbstractConfigurableHandler Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.arextest.storage.service.config;

import com.arextest.config.repository.ConfigRepositoryProvider;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;

/**
 * @author jmo
 * @since 2022/2/4
 */
public abstract class AbstractConfigurableHandler implements ConfigurableHandler {

  protected final ConfigRepositoryProvider repositoryProvider;

  protected AbstractConfigurableHandler(ConfigRepositoryProvider repositoryProvider) {
    this.repositoryProvider = repositoryProvider;
  }

  @Override
  public List useResultAsList(String appId) {
    List sourceList = repositoryProvider.listBy(appId);
    if (CollectionUtils.isEmpty(sourceList)) {
      return createFromGlobalDefault(appId);
    }
    if (this.shouldMergeGlobalDefault()) {
      for (T source : sourceList) {
        this.mergeGlobalDefaultSettings(source);
      }
    }
    return sourceList;
  }

  @Override
  public List useResultAsList() {
    return repositoryProvider.list();
  }

  @Override
  public boolean insertList(List configurationList) {
    return repositoryProvider.insertList(configurationList);
  }

  @Override
  public final boolean removeList(List configurationList) {
    return repositoryProvider.removeList(configurationList);
  }

  @Override
  public boolean insert(T configuration) {
    return repositoryProvider.insert(configuration);
  }

  @Override
  public boolean remove(T configuration) {
    return repositoryProvider.remove(configuration);
  }

  @Override
  public boolean update(T configuration) {
    return repositoryProvider.update(configuration);
  }

  protected List createFromGlobalDefault(String appId) {
    return null;
  }

  protected boolean shouldMergeGlobalDefault() {
    return false;
  }

  protected void mergeGlobalDefaultSettings(T source) {

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy