Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.ebay.jetstream.configurationmanagement.MongoConfigLogManager Maven / Gradle / Ivy
/*******************************************************************************
* Copyright © 2012-2015 eBay Software Foundation
* This program is dual licensed under the MIT and Apache 2.0 licenses.
* Please see LICENSE for more information.
*******************************************************************************/
package com.ebay.jetstream.configurationmanagement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.ebay.jetstream.config.mongo.JetStreamBeanConfigurationDo;
import com.ebay.jetstream.config.mongo.MongoConfiguration;
import com.ebay.jetstream.configurationmanagement.model.JetStreamBeanConfigurationLogDo;
import com.mongodb.BasicDBObject;
public class MongoConfigLogManager {
private MongoLogConnection mongoLogConnection;
public MongoConfigLogManager(MongoConfiguration config) throws Exception {
mongoLogConnection = new MongoLogConnection(config);
}
public List findAll() {
List beanConfigs = MongoLogDAO
.findConfigurationByAppNameAndVersion(null, mongoLogConnection);
return beanConfigs;
}
public List getJetStreamConfiguration(
String appName) {
BasicDBObject query = new BasicDBObject();
query.put("appName", appName);
List beanConfigs = MongoLogDAO
.findConfigurationByAppNameAndVersion(query, mongoLogConnection);
return beanConfigs;
}
/**
* READ FROM DB
*/
public List getJetStreamConfiguration(
String appName, String version) {
BasicDBObject query = new BasicDBObject();
query.put("appName", appName);
query.put("version", version);
List beanConfigs = MongoLogDAO
.findConfigurationByAppNameAndVersion(query, mongoLogConnection);
return beanConfigs;
}
public List getJetStreamConfiguration(
String appName, String version, String beanName) {
BasicDBObject query = new BasicDBObject();
query.put("appName", appName);
query.put("version", version);
query.put("beanName", beanName);
List beanConfigs = MongoLogDAO
.findConfigurationByAppNameAndVersion(query, mongoLogConnection);
return beanConfigs;
}
public List getJetStreamConfiguration(
String appName, String version, String beanName, String scope) {
BasicDBObject query = new BasicDBObject();
query.put("appName", appName);
query.put("version", version);
query.put("beanName", beanName);
query.put("scope", scope);
List beanConfigs = MongoLogDAO
.findConfigurationByAppNameAndVersion(query, mongoLogConnection);
return beanConfigs;
}
public List getJetStreamConfiguration(
String appName, String version, String beanName,
String beanVersion, String scope) {
BasicDBObject query = new BasicDBObject();
query.put("appName", appName);
query.put("version", version);
query.put("beanName", beanName);
query.put("beanVersion", beanVersion);
query.put("scope", scope);
List beanConfigs = MongoLogDAO
.findConfigurationByAppNameAndVersion(query, mongoLogConnection);
return beanConfigs;
}
public void uploadJetStreamConfiguration(
JetStreamBeanConfigurationLogDo beanConfigLogDo) {
BasicDBObject dbObject = new BasicDBObject();
dbObject.put("appName", beanConfigLogDo.getAppName());
dbObject.put("version", beanConfigLogDo.getVersion());
dbObject.put("scope", beanConfigLogDo.getScope());
dbObject.put("beanDefinition", beanConfigLogDo.getBeanDefinition());
dbObject.put("beanVersion", beanConfigLogDo.getBeanVersion());
dbObject.put("beanName", beanConfigLogDo.getBeanName());
dbObject.put("createdBy", beanConfigLogDo.getCreatedBy());
dbObject.put("modifiedBy", beanConfigLogDo.getModifiedBy());
dbObject.put("operatedBy", beanConfigLogDo.getOperatedBy());
dbObject.put("creationDate", beanConfigLogDo.getCreationDate());
dbObject.put("modifiedDate", beanConfigLogDo.getModifiedDate());
dbObject.put("operatedDate", beanConfigLogDo.getOperatedDate());
dbObject.put("status", beanConfigLogDo.getStatus());
MongoLogDAO.insertJetStreamConfiguration(dbObject, mongoLogConnection);
}
public int getMaxBeanVersion(String appName, String version,
String beanName, String scope) {
BasicDBObject query = new BasicDBObject();
query.put("appName", appName);
query.put("version", version);
query.put("beanName", beanName);
query.put("scope", scope);
List beanConfigs = MongoLogDAO
.findConfigurationByAppNameAndVersion(query, mongoLogConnection);
int maxVersion = -1;
for (int i = 0; i < beanConfigs.size(); i++) {
JetStreamBeanConfigurationDo config = beanConfigs.get(i);
String beanVersion = config.getBeanVersion();
int beanVersionInt = Integer.parseInt(beanVersion);
if (i == 0 || beanVersionInt > maxVersion) {
maxVersion = Integer.parseInt(beanVersion);
}
}
return maxVersion;
}
public void removeBeanLogBefore(String dateStr) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(dateStr);
BasicDBObject condition = new BasicDBObject();
condition.put("$lt", date.getTime());
BasicDBObject query = new BasicDBObject();
query.put("operatedDate", condition);
MongoLogDAO.removeConfigurationByQuery(query, mongoLogConnection);
}
}