Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
Test-Project01
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scortese
Test-Project01
Commits
2464b142
Commit
2464b142
authored
Dec 26, 2018
by
nmuthusamy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parent
88708410
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
280 deletions
+24
-280
ArticlesApplication.java
src/main/java/com/altimetrik/ArticlesApplication.java
+1
-1
ArticleController.java
...om/altimetrik/articles/controllers/ArticleController.java
+0
-63
Article.java
src/main/java/com/altimetrik/articles/entity/Article.java
+0
-107
ArticlesUtil.java
src/main/java/com/altimetrik/articles/util/ArticlesUtil.java
+0
-106
SwaggerConfig.java
src/main/java/com/altimetrik/config/SwaggerConfig.java
+2
-3
Hello.java
src/main/java/com/altimetrik/controllers/Hello.java
+21
-0
No files found.
src/main/java/com/altimetrik/
articles/
ArticlesApplication.java
→
src/main/java/com/altimetrik/ArticlesApplication.java
View file @
2464b142
package
com
.
altimetrik
.
articles
;
package
com
.
altimetrik
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
src/main/java/com/altimetrik/articles/controllers/ArticleController.java
deleted
100644 → 0
View file @
88708410
package
com
.
altimetrik
.
articles
.
controllers
;
import
java.util.Set
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
com.altimetrik.articles.entity.Article
;
import
com.altimetrik.articles.util.ArticlesUtil
;
import
java.util.ArrayList
;
import
java.util.List
;
import
lombok.extern.slf4j.Slf4j
;
@CrossOrigin
@Controller
@RequestMapping
(
"/articles"
)
@Slf4j
public
class
ArticleController
{
@Autowired
ArticlesUtil
articleUtil
;
@GetMapping
(
value
=
"/"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
consumes
=
MediaType
.
ALL_VALUE
)
public
ResponseEntity
<
List
<
Article
>>
getALL
()
{
log
.
info
(
"Inside get all method"
);
return
new
ResponseEntity
(
articleUtil
.
call
(),
HttpStatus
.
OK
);
}
@GetMapping
(
value
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
consumes
=
MediaType
.
ALL_VALUE
)
public
ResponseEntity
<
List
<
Article
>>
getById
(
@PathVariable
(
"id"
)
Integer
id
)
{
log
.
info
(
"Inside getbyId method"
);
return
new
ResponseEntity
(
articleUtil
.
call
(
id
),
HttpStatus
.
OK
);
}
@PostMapping
(
value
=
"/"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
consumes
=
MediaType
.
ALL_VALUE
)
public
ResponseEntity
<
Article
>
createArticle
(
@RequestBody
Article
article
)
{
log
.
info
(
"Inside creat method"
);
return
new
ResponseEntity
(
articleUtil
.
create
(
article
),
HttpStatus
.
OK
);
}
@PutMapping
(
value
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
consumes
=
MediaType
.
ALL_VALUE
)
public
ResponseEntity
<
Article
>
updateArticle
(
@PathVariable
(
"id"
)
Integer
id
)
{
log
.
info
(
"Inside update method"
);
try
{
return
new
ResponseEntity
(
articleUtil
.
update
(
id
),
HttpStatus
.
OK
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Error while update : {}"
,
e
.
getMessage
());
}
return
new
ResponseEntity
(
null
,
HttpStatus
.
EXPECTATION_FAILED
);
}
}
src/main/java/com/altimetrik/articles/entity/Article.java
deleted
100644 → 0
View file @
88708410
package
com
.
altimetrik
.
articles
.
entity
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
Article
implements
Comparable
<
Article
>
{
private
Integer
id
;
private
String
title
;
private
String
description
;
private
List
<
String
>
tags
=
new
ArrayList
<>();
private
Long
vote
;
private
String
createdDate
;
private
String
createdBy
;
private
String
updatedDate
;
private
String
updatedBy
;
public
Article
()
{
super
();
}
public
Article
(
Integer
id
,
String
title
,
String
description
,
List
<
String
>
tags
,
Long
vote
,
String
createdDate
,
String
createdBy
,
String
updatedDate
,
String
updatedBy
)
{
super
();
this
.
id
=
id
;
this
.
title
=
title
;
this
.
description
=
description
;
this
.
tags
=
tags
;
this
.
vote
=
vote
;
this
.
createdDate
=
createdDate
;
this
.
createdBy
=
createdBy
;
this
.
updatedDate
=
updatedDate
;
this
.
updatedBy
=
updatedBy
;
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
List
<
String
>
getTags
()
{
return
tags
;
}
public
void
setTags
(
List
<
String
>
tags
)
{
this
.
tags
=
tags
;
}
public
Long
getVote
()
{
return
vote
;
}
public
void
setVote
(
Long
vote
)
{
this
.
vote
=
vote
;
}
public
String
getCreatedDate
()
{
return
createdDate
;
}
public
void
setCreatedDate
(
String
createdDate
)
{
this
.
createdDate
=
createdDate
;
}
public
String
getCreatedBy
()
{
return
createdBy
;
}
public
void
setCreatedBy
(
String
createdBy
)
{
this
.
createdBy
=
createdBy
;
}
public
String
getUpdatedDate
()
{
return
updatedDate
;
}
public
void
setUpdatedDate
(
String
updatedDate
)
{
this
.
updatedDate
=
updatedDate
;
}
public
String
getUpdatedBy
()
{
return
updatedBy
;
}
public
void
setUpdatedBy
(
String
updatedBy
)
{
this
.
updatedBy
=
updatedBy
;
}
@Override
public
int
compareTo
(
Article
o
)
{
if
(
o
.
getVote
()
>
this
.
getVote
())
{
return
2
;
}
else
if
(
o
.
getVote
()
<
this
.
getVote
())
{
return
-
1
;
}
else
{
return
0
;
}
}
}
src/main/java/com/altimetrik/articles/util/ArticlesUtil.java
deleted
100644 → 0
View file @
88708410
package
com
.
altimetrik
.
articles
.
util
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Collections
;
import
java.util.List
;
import
javax.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
com.altimetrik.articles.controllers.ArticleController
;
import
com.altimetrik.articles.entity.Article
;
import
com.fasterxml.jackson.core.JsonParseException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
@Slf4j
@Component
public
class
ArticlesUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ArticleController
.
class
);
@Value
(
"${article.fileName}"
)
private
String
configFileName
;
public
static
List
<
Article
>
fullList
;
public
int
count
=
4
;
@PostConstruct
public
void
init
()
{
try
{
ClassLoader
classLoader
=
new
ArticlesUtil
().
getClass
().
getClassLoader
();
InputStream
io
=
classLoader
.
getResourceAsStream
(
configFileName
);
fullList
=
new
ObjectMapper
().
readValue
(
io
,
new
TypeReference
<
List
<
Article
>>()
{
});
fullList
.
forEach
(
a
->
System
.
out
.
println
(
a
.
toString
()));
log
.
info
(
"Validator json loaded successfully"
);
}
catch
(
JsonParseException
e
)
{
log
.
info
(
"Error while parsing the validator json : "
+
e
);
}
catch
(
JsonMappingException
e
)
{
log
.
info
(
"Error while mapping the validator json : "
+
e
);
}
catch
(
IOException
e
)
{
log
.
info
(
"Error while reading the validator json : "
+
e
);
}
}
public
List
<
Article
>
call
()
{
Collections
.
sort
(
fullList
);
return
fullList
;
}
public
Article
call
(
int
id
)
{
for
(
Article
article
:
fullList
)
{
if
(
article
.
getId
()
==
id
)
{
return
article
;
}
}
return
null
;
}
public
Article
create
(
Article
article
)
{
article
.
setId
(
count
);
fullList
.
add
(
article
);
count
++;
// this.addToFile();
return
article
;
}
/*
* private void addToFile() { try { URL url = new
* ArticlesUtil().getClass().getClassLoader().getResource(configFileName);
* FileWriter f = new FileWriter(url.toURI().getPath()); Gson gson = new
* Gson();
*
* f.write(gson.toJson(fullList)); f.close(); } catch (URISyntaxException e)
* { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
*
* }
*/
public
Article
update
(
int
id
)
throws
Exception
{
Article
obj
=
this
.
call
(
id
);
if
(
fullList
.
remove
(
obj
))
{
Long
l
=
obj
.
getVote
();
obj
.
setVote
(++
l
);
fullList
.
add
(
obj
);
}
else
{
throw
new
Exception
(
"No data found to update"
);
}
// addToFile();
return
obj
;
}
}
src/main/java/com/altimetrik/
articles/
config/SwaggerConfig.java
→
src/main/java/com/altimetrik/config/SwaggerConfig.java
View file @
2464b142
...
...
@@ -6,13 +6,12 @@
* and shall use it only in accordance with the terms and conditions
* entered into with Altimetrik.
*/
package
com
.
altimetrik
.
articles
.
config
;
package
com
.
altimetrik
.
config
;
import
static
springfox
.
documentation
.
builders
.
PathSelectors
.
regex
;
import
java.util.Collections
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -44,7 +43,7 @@ public class SwaggerConfig {
private
ApiInfo
metaData
()
{
return
new
ApiInfo
(
"Playground A
uthentication and Authorization"
,
"Playground API Services for Articl
es"
,
"2.0"
,
return
new
ApiInfo
(
"Playground A
pplication"
,
"Playground API Servic
es"
,
"2.0"
,
"https://www.altimetrik.com/privacy-policy/"
,
new
Contact
(
"Playground"
,
"https://playground.altimetrik.com"
,
"pg-mgr1@altimetrik.com"
),
"Apache License Version 2.0"
,
"https://www.apache.org/licenses/LICENSE-2.0"
,
Collections
.
emptyList
());
}
...
...
src/main/java/com/altimetrik/controllers/Hello.java
0 → 100644
View file @
2464b142
package
com
.
altimetrik
.
controllers
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
value
=
"/hello"
)
public
class
Hello
{
@GetMapping
(
value
=
"/"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
consumes
=
MediaType
.
ALL_VALUE
)
public
ResponseEntity
<
String
>
getUserDetailByGitlabEmailId
()
{
return
new
ResponseEntity
<>(
"Wecome to Playground..."
,
HttpStatus
.
OK
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment