Skip to content

Commit befff72

Browse files
committed
Solution
1 parent 6eb94dc commit befff72

File tree

91 files changed

+1294
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1294
-1
lines changed

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
# AWStest
1+
# AWStest
2+
3+
Create a webapp which has two sections.
4+
5+
Section 1 : You can upload any valid pic(JPG/PNG), pdf or word doc only with limit 2MB.
6+
7+
Section 2 : Here you can see the listing of all your documents. (URL only)
8+
9+
10+
Technology stack :
11+
Spring MVC
12+
Hibernate
13+
MySQL : A table which consists all the generated S3 URLs
14+
AWS S3 : All the documents will be uploaded on this server and there is a specific public URL of it.
15+
Don't forget client and server side validation.
16+
Don't focus too much on UI part, simple bootstrap would be enough. Focus on functionality.
17+
18+
Help
19+
http://docs.aws.amazon.com/AmazonS3/latest/UG/Welcome.html
20+
21+
22+
S3 Test Credentials
23+
Access Key ID: XXXXX
24+
Secret Access Key: XXXXXX

db/db.sql

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
SQLyog Community v11.26 (64 bit)
3+
MySQL - 5.6.17 : Database - testdb
4+
*********************************************************************
5+
*/
6+
7+
/*!40101 SET NAMES utf8 */;
8+
9+
/*!40101 SET SQL_MODE=''*/;
10+
11+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
12+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
13+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
14+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
15+
CREATE DATABASE /*!32312 IF NOT EXISTS*/`testdb` /*!40100 DEFAULT CHARACTER SET latin1 */;
16+
17+
USE `testdb`;
18+
19+
/*Table structure for table `files` */
20+
21+
DROP TABLE IF EXISTS `files`;
22+
23+
CREATE TABLE `files` (
24+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
25+
`name` varchar(255) NOT NULL,
26+
`file_uri` varchar(255) DEFAULT NULL,
27+
`created_at` datetime NOT NULL,
28+
PRIMARY KEY (`id`),
29+
UNIQUE KEY `UNQ_IDX` (`file_uri`)
30+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
31+
32+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
33+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
34+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
35+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

pom.xml

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.awsapp</groupId>
6+
<artifactId>AWStest</artifactId>
7+
<name>AWStest</name>
8+
<packaging>war</packaging>
9+
<version>1.0.0-BUILD-SNAPSHOT</version>
10+
11+
<properties>
12+
<java-version>1.8</java-version>
13+
<org.springframework-version>4.0.3.RELEASE</org.springframework-version>
14+
<org.aspectj-version>1.7.4</org.aspectj-version>
15+
<org.slf4j-version>1.7.5</org.slf4j-version>
16+
<hibernate.version>4.3.5.Final</hibernate.version>
17+
</properties>
18+
<dependencies>
19+
<!-- Spring -->
20+
<dependency>
21+
<groupId>org.springframework</groupId>
22+
<artifactId>spring-context</artifactId>
23+
<version>${org.springframework-version}</version>
24+
<exclusions>
25+
<!-- Exclude Commons Logging in favor of SLF4j -->
26+
<exclusion>
27+
<groupId>commons-logging</groupId>
28+
<artifactId>commons-logging</artifactId>
29+
</exclusion>
30+
</exclusions>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework</groupId>
34+
<artifactId>spring-webmvc</artifactId>
35+
<version>${org.springframework-version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-tx</artifactId>
40+
<version>${org.springframework-version}</version>
41+
</dependency>
42+
43+
<!-- Hibernate -->
44+
<dependency>
45+
<groupId>org.hibernate</groupId>
46+
<artifactId>hibernate-core</artifactId>
47+
<version>${hibernate.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.hibernate</groupId>
51+
<artifactId>hibernate-entitymanager</artifactId>
52+
<version>${hibernate.version}</version>
53+
</dependency>
54+
55+
<!-- Apache Commons DBCP -->
56+
<dependency>
57+
<groupId>commons-dbcp</groupId>
58+
<artifactId>commons-dbcp</artifactId>
59+
<version>1.4</version>
60+
</dependency>
61+
<!-- Spring ORM -->
62+
<dependency>
63+
<groupId>org.springframework</groupId>
64+
<artifactId>spring-orm</artifactId>
65+
<version>${org.springframework-version}</version>
66+
</dependency>
67+
68+
<!-- AspectJ -->
69+
<dependency>
70+
<groupId>org.aspectj</groupId>
71+
<artifactId>aspectjrt</artifactId>
72+
<version>${org.aspectj-version}</version>
73+
</dependency>
74+
75+
<!-- Logging -->
76+
<dependency>
77+
<groupId>org.slf4j</groupId>
78+
<artifactId>slf4j-api</artifactId>
79+
<version>${org.slf4j-version}</version>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.slf4j</groupId>
83+
<artifactId>jcl-over-slf4j</artifactId>
84+
<version>${org.slf4j-version}</version>
85+
<scope>runtime</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.slf4j</groupId>
89+
<artifactId>slf4j-log4j12</artifactId>
90+
<version>${org.slf4j-version}</version>
91+
92+
<scope>runtime</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>log4j</groupId>
96+
<artifactId>log4j</artifactId>
97+
<version>1.2.15</version>
98+
<exclusions>
99+
<exclusion>
100+
<groupId>javax.mail</groupId>
101+
<artifactId>mail</artifactId>
102+
</exclusion>
103+
<exclusion>
104+
<groupId>javax.jms</groupId>
105+
<artifactId>jms</artifactId>
106+
</exclusion>
107+
<exclusion>
108+
<groupId>com.sun.jdmk</groupId>
109+
<artifactId>jmxtools</artifactId>
110+
</exclusion>
111+
<exclusion>
112+
<groupId>com.sun.jmx</groupId>
113+
<artifactId>jmxri</artifactId>
114+
</exclusion>
115+
</exclusions>
116+
<scope>runtime</scope>
117+
118+
</dependency>
119+
120+
<!-- @Inject -->
121+
<dependency>
122+
<groupId>javax.inject</groupId>
123+
<artifactId>javax.inject</artifactId>
124+
<version>1</version>
125+
</dependency>
126+
127+
<!-- Servlet -->
128+
<dependency>
129+
<groupId>javax.servlet</groupId>
130+
<artifactId>servlet-api</artifactId>
131+
<version>2.5</version>
132+
<scope>provided</scope>
133+
</dependency>
134+
<dependency>
135+
<groupId>javax.servlet.jsp</groupId>
136+
<artifactId>jsp-api</artifactId>
137+
<version>2.1</version>
138+
<scope>provided</scope>
139+
</dependency>
140+
<dependency>
141+
<groupId>javax.servlet</groupId>
142+
<artifactId>jstl</artifactId>
143+
<version>1.2</version>
144+
</dependency>
145+
146+
<dependency>
147+
<groupId>mysql</groupId>
148+
<artifactId>mysql-connector-java</artifactId>
149+
<version>5.1.6</version>
150+
</dependency>
151+
152+
<dependency>
153+
<groupId>com.amazonaws</groupId>
154+
<artifactId>aws-java-sdk-s3</artifactId>
155+
<version>1.10.20</version>
156+
</dependency>
157+
<dependency>
158+
<groupId>commons-fileupload</groupId>
159+
<artifactId>commons-fileupload</artifactId>
160+
<version>1.3</version>
161+
</dependency>
162+
163+
</dependencies>
164+
<build>
165+
<plugins>
166+
<plugin>
167+
<artifactId>maven-eclipse-plugin</artifactId>
168+
<version>2.9</version>
169+
<configuration>
170+
<additionalProjectnatures>
171+
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
172+
</additionalProjectnatures>
173+
<additionalBuildcommands>
174+
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
175+
</additionalBuildcommands>
176+
<downloadSources>true</downloadSources>
177+
<downloadJavadocs>true</downloadJavadocs>
178+
</configuration>
179+
</plugin>
180+
<plugin>
181+
<groupId>org.apache.maven.plugins</groupId>
182+
<artifactId>maven-compiler-plugin</artifactId>
183+
<version>2.5.1</version>
184+
<configuration>
185+
<source>1.6</source>
186+
<target>1.6</target>
187+
<compilerArgument>-Xlint:all</compilerArgument>
188+
<showWarnings>true</showWarnings>
189+
<showDeprecation>true</showDeprecation>
190+
</configuration>
191+
</plugin>
192+
<plugin>
193+
<groupId>org.codehaus.mojo</groupId>
194+
<artifactId>exec-maven-plugin</artifactId>
195+
<version>1.2.1</version>
196+
<configuration>
197+
<mainClass>org.test.int1.Main</mainClass>
198+
</configuration>
199+
</plugin>
200+
</plugins>
201+
<finalName>${project.artifactId}</finalName>
202+
</build>
203+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.awsapp.configs;
2+
3+
public class AWS {
4+
5+
public static String s3AccessKey="XXX";
6+
public static String s3AccessSecret="XXX";
7+
public static String uploadPath="F:/cp/";
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.awsapp.controller;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.beans.factory.annotation.Qualifier;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.ui.Model;
7+
import org.springframework.web.bind.annotation.ModelAttribute;
8+
import org.springframework.web.bind.annotation.PathVariable;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestMethod;
11+
import java.io.BufferedOutputStream;
12+
import java.io.File;
13+
import org.springframework.web.multipart.MultipartFile;
14+
import java.io.FileOutputStream;
15+
16+
17+
import com.awsapp.model.Files;
18+
import com.awsapp.service.FilesService;
19+
import com.awsapp.util.*;
20+
21+
import com.awsapp.configs.AWS;
22+
23+
@Controller
24+
public class FileController {
25+
26+
private FilesService filesService;
27+
28+
@Autowired(required=true)
29+
@Qualifier(value="filesService")
30+
public void setFilesService(FilesService fs){
31+
this.filesService = fs;
32+
}
33+
34+
@RequestMapping(value = "/files", method = RequestMethod.GET)
35+
public String listFiless(Model model) {
36+
model.addAttribute("file", new Files());
37+
model.addAttribute("listFiles", this.filesService.listFiles());
38+
return "file";
39+
}
40+
41+
@RequestMapping(value= "/file/add/**", method = RequestMethod.GET)
42+
public String redirectToFileList(){
43+
return "redirect:/files";
44+
}
45+
46+
//For add and update person both
47+
@RequestMapping(value= "/file/add", method = RequestMethod.POST)
48+
public String addFile(@ModelAttribute("file") MultipartFile file,Model model){
49+
50+
String msg=null;
51+
String fileName = null;
52+
if (!file.isEmpty()) {
53+
try {
54+
fileName = file.getOriginalFilename();
55+
byte[] bytes = file.getBytes();
56+
String path=AWS.uploadPath + fileName;
57+
BufferedOutputStream buffStream =
58+
new BufferedOutputStream(new FileOutputStream(new File(path)));
59+
buffStream.write(bytes);
60+
buffStream.close();
61+
62+
63+
AwsS3 aws=new AwsS3();
64+
String s3accesUri=aws.s3Upload(path, fileName);
65+
Files newFile=new Files();
66+
newFile.setFileUri(s3accesUri);
67+
newFile.setCreatedAt(com.awsapp.util.DateTime.getCurrentDateTimeForMySQL());
68+
this.filesService.addFile(newFile);
69+
70+
// msg= "You have successfully uploaded " + fileName;
71+
return "redirect:/files";
72+
} catch (Exception e) {
73+
msg= "You failed to upload " + fileName + ": " + e.getMessage();
74+
}
75+
} else {
76+
msg= "Unable to upload. File is empty.";
77+
}
78+
model.addAttribute("msg", msg);
79+
80+
System.out.print(msg);
81+
model.addAttribute("file", new Files());
82+
model.addAttribute("listFiles", this.filesService.listFiles());
83+
return "file";
84+
85+
86+
87+
88+
89+
}
90+
91+
92+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.awsapp.dao;
2+
3+
import java.util.List;
4+
5+
import com.awsapp.model.Files;
6+
7+
public interface FilesDAO {
8+
9+
public void addFile(Files file);
10+
11+
public List<Files> listFiles();
12+
13+
14+
}

0 commit comments

Comments
 (0)