Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.3: support plugin external storage service for blog persistent
- Loading branch information
1 parent
b5cd4ad
commit cab2016
Showing
101 changed files
with
4,201 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ lib | |
.dbshell | ||
*.iml | ||
*.eml | ||
*.ipl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package controllers; | ||
|
||
import com.greenlaw110.storage.ISObject; | ||
import com.greenlaw110.util.F; | ||
import com.greenlaw110.util.S; | ||
import play.cache.Cache; | ||
import play.modules.morphia.Blob; | ||
import play.modules.morphia.BlobStorageService; | ||
import play.mvc.Controller; | ||
|
||
/** | ||
* A generic blob viewer | ||
*/ | ||
public class BlobViewer extends Controller { | ||
public static void view(String key) { | ||
notFoundIfNull(key); | ||
Blob blob; | ||
if (key.endsWith(Blob.TMP_ID_SUFFIX)) { | ||
blob = Cache.get(key, Blob.class); | ||
notFoundIfNull(blob); | ||
} else { | ||
if (!key.contains("-")) { | ||
ISObject sobj = Cache.get(key, ISObject.class); | ||
notFoundIfNull(sobj); | ||
response.setContentTypeIfNotSet(sobj.getAttribute(ISObject.ATTR_CONTENT_TYPE)); | ||
renderBinary(sobj.asInputStream()); | ||
} | ||
F.Str s = S.str(key); | ||
String ssKey = s.afterLast("-").get(); | ||
BlobStorageService bss = BlobStorageService.getService(ssKey); | ||
String objKey = s.beforeFirst("-").get(); | ||
ISObject sobj = bss.get(objKey); | ||
if (null == objKey) { | ||
sobj = Cache.get(key, ISObject.class); | ||
} | ||
notFoundIfNull(sobj); | ||
blob = new Blob(sobj, bss); | ||
} | ||
if (!blob.exists()) { | ||
notFound(); | ||
} | ||
response.setContentTypeIfNotSet(blob.type()); | ||
renderBinary(blob.get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GET /blob/{id} BlobViewer.view |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project version="4"> | ||
<component name="ProjectModuleManager"> | ||
<modules> | ||
<module fileurl="file://$PROJECT_DIR$/album.iml" filepath="$PROJECT_DIR$/album.iml" /> | ||
</modules> | ||
</component> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package controllers; | ||
|
||
import models.Album; | ||
import models.Photo; | ||
import play.cache.Cache; | ||
import play.modules.morphia.Blob; | ||
import play.mvc.Controller; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Application extends Controller { | ||
|
||
public static void index() { | ||
List<Album> albums = Album.findAll(); | ||
render(albums); | ||
} | ||
|
||
public static void album(String albumId) { | ||
Album album = Album.findById(albumId); | ||
notFoundIfNull(album); | ||
|
||
render(album); | ||
} | ||
|
||
public static void albumForm(String albumId) { | ||
Album album; | ||
if (null != albumId) { | ||
album = Album.findById(albumId); | ||
notFoundIfNull(album); | ||
} else { | ||
album = new Album(); | ||
} | ||
render(album); | ||
} | ||
|
||
public static void saveAlbum(Album album) { | ||
album.save(); | ||
album(album.getIdAsStr()); | ||
} | ||
|
||
private static String photoCacheKey() { | ||
return session.getId() + ":photo"; | ||
} | ||
|
||
public static void newPhotoForm(String albumId) { | ||
Album album = Album.findById(albumId); | ||
notFoundIfNull(album); | ||
|
||
Photo photo = new Photo(albumId); | ||
Cache.set(photoCacheKey(), photo); | ||
render(album); | ||
} | ||
|
||
public static void deletePhoto(String photoId) { | ||
Photo photo = Photo.findById(photoId); | ||
notFoundIfNull(photo); | ||
photo.delete(); | ||
album(photo.albumId); | ||
} | ||
|
||
public static void upload(File file) { | ||
Photo photo = Cache.get(photoCacheKey(), Photo.class); | ||
notFoundIfNull(photo); | ||
|
||
photo.blob = new Blob(file); | ||
} | ||
|
||
public static void savePhoto(String desc, String tags) { | ||
Photo photo = Cache.get(photoCacheKey(), Photo.class); | ||
notFoundIfNull(photo); | ||
|
||
photo.desc = desc; | ||
if (null != tags) { | ||
photo.tags.addAll(Arrays.asList(tags.split("[,; ]+"))); | ||
} | ||
photo.save(); | ||
|
||
Cache.delete(photoCacheKey()); | ||
|
||
album(photo.albumId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package models; | ||
|
||
import com.google.code.morphia.annotations.Entity; | ||
import play.modules.morphia.Model; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: luog | ||
* Date: 11/06/13 | ||
* Time: 9:18 PM | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
@Entity("albumn") | ||
public class Album extends Model { | ||
public String name; | ||
public Set<String> tags; | ||
|
||
public Album() { | ||
init(); | ||
} | ||
|
||
public List<Photo> getPhotos() { | ||
return Photo.find("albumId", this.getId()).asList(); | ||
} | ||
|
||
@Model.Loaded | ||
void init() { | ||
if (null == tags) { | ||
tags = new HashSet<String>(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package models; | ||
|
||
import com.google.code.morphia.annotations.Entity; | ||
import play.modules.morphia.Blob; | ||
import play.modules.morphia.Model; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: luog | ||
* Date: 11/06/13 | ||
* Time: 9:19 PM | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
@Entity("photo") | ||
public class Photo extends Model { | ||
public String albumId; | ||
public String desc; | ||
|
||
public Blob blob; | ||
public Set<String> tags; | ||
|
||
public Photo(String albumId) { | ||
init(); | ||
this.albumId = albumId; | ||
} | ||
|
||
@Model.Loaded | ||
void init() { | ||
if (null == tags) { | ||
tags = new HashSet<String>(); | ||
} | ||
} | ||
|
||
public String getUrl() { | ||
return null == blob ? null: blob.getUrl(); | ||
//return null; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@extends(main) | ||
|
||
@args Album album | ||
|
||
<h1>Album - @album.name</h1> | ||
|
||
<style type="text/css"> | ||
ul.gallery { | ||
list-style: none; | ||
margin-left: 0; | ||
} | ||
</style> | ||
|
||
<ul class="gallery"> | ||
@for(Photo photo: album.getPhotos()) { | ||
<li class="photo"> | ||
<img src="@photo.getUrl()"> | ||
<div class="desc"> | ||
@photo.desc | ||
</div> | ||
<div> | ||
<a class="btn" href="@url('deletePhoto(photo.getIdAsStr())')">Delete</a> | ||
</div> | ||
</li> | ||
} else { | ||
<li class="alert alert-info"> | ||
No photo found in this album | ||
</li> | ||
} | ||
</ul> | ||
|
||
<div> | ||
<a class="btn" href="@url('newPhotoForm(album.getIdAsStr())')">Add photo</a> | ||
</div> |
20 changes: 20 additions & 0 deletions
20
samples-and-tests/album/app/rythm/Application/albumForm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@extends(main) | ||
|
||
@args Album album | ||
|
||
<h1> | ||
@if(album.isNew()){ | ||
Create new album | ||
} else { | ||
Edit album - @album.name | ||
} | ||
</h1> | ||
<form action="@url(saveAlbum)" method="post"> | ||
<div> | ||
<label>Name</label> | ||
<input type="text" name="album.name" value="@album.name"> | ||
</div> | ||
<div> | ||
<button class="btn">Submit</button> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@extends(main) | ||
|
||
@args List<Album> albums | ||
|
||
<ul> | ||
@for(albums) { | ||
<li> | ||
<a href="@url(album(_.getId()))">@_.name</a> | ||
</li> | ||
} else { | ||
<div class="alert alert-info">There is no album created yet</div> | ||
} | ||
</ul> | ||
|
||
<div> | ||
<a href="@url(albumForm)" class="btn">Create new album</a> | ||
</div> |
Oops, something went wrong.