Permalink
Browse files

Adding cloud summary page

  • Loading branch information...
trisberg committed Oct 6, 2011
1 parent e820166 commit dcb1af1a893afc3e1b084db4d9a13b2d78c309e6
View
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
View
@@ -3,7 +3,6 @@
<name>visitors</name>
<comment></comment>
<projects>
- <project>Servers</project>
</projects>
<buildSpec>
<buildCommand>
@@ -22,30 +21,23 @@
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.springframework.ide.eclipse.core.springbuilder</name>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
- <nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
- <nature>org.springframework.ide.eclipse.core.springnature</nature>
- <nature>com.springsource.sts.roo.core.nature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>
View
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/webapp"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
+ <attributes>
+ <attribute name="hide" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
@@ -1,43 +0,0 @@
-#Thu Sep 22 12:20:43 EDT 2011
-eclipse.preferences.version=1
-org.aspectj.ajdt.core.compiler.BuildOptions.showweavemessages=false
-org.aspectj.ajdt.core.compiler.lint.BrokeSerialVersionCompatibility=ignore
-org.aspectj.ajdt.core.compiler.lint.CannotImplementLazyTJP=ignore
-org.aspectj.ajdt.core.compiler.lint.InvalidAbsoluteTypeName=warning
-org.aspectj.ajdt.core.compiler.lint.NeedSerialVersionUIDField=ignore
-org.aspectj.ajdt.core.compiler.lint.NoInterfaceCtorJoinpoint=warning
-org.aspectj.ajdt.core.compiler.lint.ShadowNotInStructure=ignore
-org.aspectj.ajdt.core.compiler.lint.TypeNotExposedToWeaver=warning
-org.aspectj.ajdt.core.compiler.lint.UnresolvableMember=warning
-org.aspectj.ajdt.core.compiler.lint.WildcardTypeName=ignore
-org.aspectj.ajdt.core.compiler.lint.adviceDidNotMatch=warning
-org.aspectj.ajdt.core.compiler.lint.annotationAsTargetForDecpIgnored=warning
-org.aspectj.ajdt.core.compiler.lint.calculatingSerialVersionUID=ignore
-org.aspectj.ajdt.core.compiler.lint.cantFindType=error
-org.aspectj.ajdt.core.compiler.lint.cantFindTypeAffectingJPMatch=warning
-org.aspectj.ajdt.core.compiler.lint.cantMatchArrayTypeOnVarargs=ignore
-org.aspectj.ajdt.core.compiler.lint.elementAlreadyAnnotated=warning
-org.aspectj.ajdt.core.compiler.lint.enumAsTargetForDecpIgnored=warning
-org.aspectj.ajdt.core.compiler.lint.invalidTargetForAnnotation=warning
-org.aspectj.ajdt.core.compiler.lint.multipleAdviceStoppingLazyTjp=ignore
-org.aspectj.ajdt.core.compiler.lint.noExplicitConstructorCall=warning
-org.aspectj.ajdt.core.compiler.lint.noGuardForLazyTjp=ignore
-org.aspectj.ajdt.core.compiler.lint.noJoinpointsForBridgeMethods=warning
-org.aspectj.ajdt.core.compiler.lint.runtimeExceptionNotSoftened=warning
-org.aspectj.ajdt.core.compiler.lint.swallowedExceptionInCatchBlock=ignore
-org.aspectj.ajdt.core.compiler.lint.uncheckedAdviceConversion=warning
-org.aspectj.ajdt.core.compiler.lint.uncheckedArgument=warning
-org.aspectj.ajdt.core.compiler.lint.unmatchedTargetKind=warning
-org.aspectj.ajdt.core.compiler.lint.unorderedAdviceAtShadow=ignore
-org.aspectj.ajdt.core.compiler.list.UnmatchedSuperTypeInCall=warning
-org.aspectj.ajdt.core.compiler.weaver.XHasMember=false
-org.aspectj.ajdt.core.compiler.weaver.XNoInline=false
-org.aspectj.ajdt.core.compiler.weaver.XNotReweavable=false
-org.aspectj.ajdt.core.compiler.weaver.XSerializableAspects=false
-org.aspectj.ajdt.core.compiler.weaver.outxml=true
-org.aspectj.ajdt.core.compiler.weaver.timers=false
-org.aspectj.ajdt.core.compiler.weaver.verbose=false
-org.aspectj.ajdt.core.complier.lint.aspectExcludedByConfiguration=ignore
-org.eclipse.ajdt.core.builder.incrementalCompilationOptimizations=true
-org.eclipse.ajdt.core.compiler.nonStandardOptions=
-org.eclipse.ajdt.core.compiler.useProjectSettings=true
@@ -0,0 +1,9 @@
+#Wed Oct 05 18:07:44 EDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,5 @@
+#Wed Oct 05 18:07:44 EDT 2011
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+ <wb-module deploy-name="visitors">
+ <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
+ <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
+ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
+ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
+ <property name="context-root" value="visitors"/>
+ <property name="java-output-path" value="/visitors/target/classes"/>
+ </wb-module>
+</project-modules>
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <fixed facet="wst.jsdt.web"/>
+ <installed facet="java" version="1.6"/>
+ <installed facet="jst.web" version="2.5"/>
+ <installed facet="wst.jsdt.web" version="1.0"/>
+</faceted-project>
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
@@ -0,0 +1 @@
+Window
View
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beansProjectDescription>
- <version>1</version>
- <pluginVersion><![CDATA[2.5.0.201010141000-RC1]]></pluginVersion>
- <configSuffixes>
- <configSuffix><![CDATA[xml]]></configSuffix>
- </configSuffixes>
- <enableImports><![CDATA[true]]></enableImports>
- <configs>
- </configs>
- <configSets>
- </configSets>
-</beansProjectDescription>
@@ -0,0 +1,36 @@
+package org.cloudfoundry.demo;
+
+import org.bson.types.ObjectId;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document
+public class Cloud {
+
+ @Id
+ ObjectId id;
+
+ String address;
+
+ Long visitCount;
+
+ public ObjectId getId() {
+ return id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public Long getVisitCount() {
+ return visitCount;
+ }
+
+ public void setVisitCount(Long visitCount) {
+ this.visitCount = visitCount;
+ }
+}
@@ -0,0 +1,78 @@
+package org.cloudfoundry.demo;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.data.mongodb.core.CollectionCallback;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Repository;
+import org.springframework.web.client.RestTemplate;
+
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoException;
+
+@Repository
+public class CloudRepository {
+
+ private final static String CLOUDS = "clouds";
+
+ @Autowired
+ private MongoTemplate mongoTemplate;
+
+ public List<Cloud> getClouds() {
+ List<Cloud> clouds = mongoTemplate.findAll(Cloud.class, CLOUDS);
+ for (Cloud cloud : clouds) {
+ Long count = getCloudCount(cloud.address);
+ if (count != null) {
+ cloud.setVisitCount(count);
+ saveCloud(cloud);
+ }
+ }
+ return clouds;
+ }
+
+ public void saveCloud(Cloud cloud) {
+ mongoTemplate.save(cloud, CLOUDS);
+ }
+
+ public void deleteCloud(String id) {
+ Query query = new Query(Criteria.where("id").is(id));
+ mongoTemplate.remove(query, CLOUDS);
+ }
+
+ public String getDump() {
+ final StringBuilder mongoData = new StringBuilder();
+ mongoTemplate.execute(CLOUDS,
+ new CollectionCallback<String>() {
+ public String doInCollection(DBCollection collection) throws MongoException, DataAccessException {
+ for (DBObject dbo : collection.find()) {
+ mongoData.append(dbo.toString());
+ mongoData.append(" ");
+ }
+ return null;
+ }
+ });
+ return mongoData.toString();
+ }
+
+ private Long getCloudCount(String address) {
+ RestTemplate rt = new RestTemplate();
+ String value;
+ try {
+ value = rt.getForObject(address + "/count", String.class);
+ } catch (Exception e) {
+ return null;
+ }
+ Long ret;
+ try {
+ ret = Long.valueOf(value);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ return ret;
+ }
+}
@@ -2,6 +2,7 @@
import java.text.DateFormat;
import java.util.Date;
+import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
@@ -11,7 +12,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
-import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -26,6 +28,9 @@
@Autowired
private VisitRepository visitRepository;
+ @Autowired
+ private CloudRepository cloudRepository;
+
/**
* Simply selects the home view to render by returning its name.
*/
@@ -54,14 +59,50 @@ public String home(Locale locale, Model model, HttpServletRequest request) {
return "home";
}
- @RequestMapping(value={"/dump"}, method=RequestMethod.GET)
+ @RequestMapping(value="/clouds", method=RequestMethod.GET)
+ public String clouds(Model model) {
+ List<Cloud> clouds = cloudRepository.getClouds();
+ long total = 0;
+ for (Cloud cloud : clouds) {
+ if (cloud.getVisitCount() != null) {
+ total += cloud.getVisitCount();
+ }
+ }
+ model.addAttribute("cloudList", clouds);
+ model.addAttribute("cloud", new Cloud());
+ model.addAttribute("total", total);
+ return "clouds";
+ }
+
+ @RequestMapping(value="/cloud/delete/{cloudId}", method=RequestMethod.GET)
+ public String cloudDelete(@PathVariable("cloudId") String cloudId) {
+ cloudRepository.deleteCloud(cloudId);
+ return "redirect:/clouds";
+ }
+
+ @RequestMapping(value="/clouds", method=RequestMethod.POST)
+ public String addCloud(@ModelAttribute("cloud") Cloud newCloud) {
+ if (newCloud != null) {
+ cloudRepository.saveCloud(newCloud);
+ }
+ return "redirect:/clouds";
+ }
+
+ @RequestMapping(value="/count", method=RequestMethod.GET)
+ public String count(Model model) {
+ model.addAttribute("count", visitRepository.getCount());
+ return "count";
+ }
+
+ @RequestMapping(value="/dump", method=RequestMethod.GET)
public String dump(Model model) {
model.addAttribute("aggregates", visitRepository.getAggregates());
model.addAttribute("mongodata", visitRepository.getDump());
+ model.addAttribute("clouds", cloudRepository.getDump());
return "dump";
}
- @RequestMapping(value={"/clear"}, method=RequestMethod.GET)
+ @RequestMapping(value="/clear", method=RequestMethod.GET)
public String clear(Model model) {
visitRepository.clear();
return "redirect:/";
@@ -78,6 +78,10 @@ public String doInCollection(DBCollection collection) throws MongoException, Dat
return aggregateData.toString();
}
+ public Long getCount() {
+ return mongoTemplate.getCollection(mongoTemplate.getCollectionName(Visit.class)).count();
+ }
+
public String getDump() {
final StringBuilder mongoData = new StringBuilder();
mongoTemplate.execute(LAST10,
Oops, something went wrong.

0 comments on commit dcb1af1

Please sign in to comment.