Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/instagrim/target/
36 changes: 36 additions & 0 deletions instagrim/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Instagrim is an example web app using Cassandra as a back end. The app allows picture uploads, creates a thumbnail and
a B/W version of the picture, and a simple login.

See Keyspaces.java for a definition of the keyspaces.
CassandraHosts manages the connections.
The code uses org.imgscalr.Scalr for image manipulation
It is a Netbeans maven based project.


The code is used as an example for AC32007, School of Computing, Univeristy of Dundee.

It implements the following URL patterns:

/Image/*
/Images
/Thumb/*
/Images/*
/Login
/Register

Not all work 100% correctly . Some parts of the implementation are missing.

Students are exected to:
1: Understand the code
2: Fix any bugs
3: Add functionality

Some ideas for added functionality you might like to add (not all are simple, you decide what are and which you’d like to try).

1: Extend the registration process and display a profile for users (add “\profile\*” for instance)
2: Upload a users picture to the users profile
3: Add image filters. So /alter/filername/* would create a new version of the picture with that filter applied.
4: Allow users to comment on other users pictures. /Image/Comments/* would display the picture with the comments.

This is not a limit to what you could do, use your imagination !

19 changes: 19 additions & 0 deletions instagrim/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
</properties>
</project-shared-configuration>
96 changes: 96 additions & 0 deletions instagrim/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>uk.ac.dundee.computing.aec</groupId>
<artifactId>Instagrim</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>Instagrim</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.eaio.uuid</groupId>
<artifactId>uuid</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package uk.ac.dundee.computing.aec.instagrim.lib;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class AeSimpleSHA1 {

private static String convertToHex(byte[] data) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do {
if ((0 <= halfbyte) && (halfbyte <= 9))
buf.append((char) ('0' + halfbyte));
else
buf.append((char) ('a' + (halfbyte - 10)));
halfbyte = data[i] & 0x0F;
} while(two_halfs++ < 1);
}
return buf.toString();
}

public static String SHA1(String text)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest md;
md = MessageDigest.getInstance("SHA-1");
byte[] sha1hash = new byte[40];
md.update(text.getBytes("iso-8859-1"), 0, text.length());
sha1hash = md.digest();
return convertToHex(sha1hash);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package uk.ac.dundee.computing.aec.instagrim.lib;

import com.datastax.driver.core.*;

import java.util.Iterator;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;

/**
* ********************************************************
*
*
* @author administrator
*
* Hosts are 192.168.2.10 Seed for Vagrant hosts
*
*
*
*
*/
public final class CassandraHosts {

private static Cluster cluster;
static String Host = "127.0.0.1"; //at least one starting point to talk to

public CassandraHosts() {

}

public static String getHost() {
return (Host);
}

public static String[] getHosts(Cluster cluster) {

if (cluster == null) {
System.out.println("Creating cluster connection");
cluster = Cluster.builder().addContactPoint(Host).build();
}
System.out.println("Cluster Name " + cluster.getClusterName());
Metadata mdata = cluster.getMetadata();
Set<Host> hosts = mdata.getAllHosts();
String sHosts[] = new String[hosts.size()];

Iterator<Host> it = hosts.iterator();
int i = 0;
while (it.hasNext()) {
Host ch = it.next();
sHosts[i] = (String) ch.getAddress().toString();

System.out.println("Hosts" + ch.getAddress().toString());
i++;
}

return sHosts;
}

public static Cluster getCluster() {
System.out.println("getCluster");
cluster = Cluster.builder()
.addContactPoint(Host).build();
getHosts(cluster);
Keyspaces.SetUpKeySpaces(cluster);

return cluster;

}

public void close() {
cluster.close();
}

}
Loading