Skip to content

Commit

Permalink
Merge pull request #46 from miguelfc/charts_extended
Browse files Browse the repository at this point in the history
Charts extended
  • Loading branch information
miguelfc authored May 9, 2017
2 parents 4058327 + f4210f3 commit 4e1f98c
Show file tree
Hide file tree
Showing 43 changed files with 1,730 additions and 285 deletions.
9 changes: 9 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ services:

processor-sklearn:
image: miguelfc/marble-processor-sklearn
ports:
- "8080"
depends_on:
- registry
links:
- registry

plotter-dous:
image: miguelfc/marble-plotter-dous
ports:
- "8080"
depends_on:
Expand Down
7 changes: 1 addition & 6 deletions marble-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.marble</groupId>
<artifactId>marble-core</artifactId>
<version>1.0.4-RELEASE</version>
<version>1.1.0-RELEASE</version>

<properties>
<java.version>1.8</java.version>
Expand Down Expand Up @@ -51,11 +51,6 @@
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.marble</groupId>
<artifactId>marble-model</artifactId>
<version>1.0.1-RELEASE</version>
</dependency>
<dependency>
<!-- Setup Spring Boot -->
<groupId>org.springframework.boot</groupId>
Expand Down
3 changes: 2 additions & 1 deletion marble-core/src/main/docker/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Supported tags and respective `Dockerfile` links

- [`1.0.4-RELEASE`, `latest`]
- [`1.1.0-RELEASE`, `latest`]
- [`1.0.4-RELEASE`]
- [`1.0.3-RELEASE`]
- [`1.0.2-RELEASE`]
- [`1.0.1-RELEASE`]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ protected void configure(HttpSecurity http) throws Exception {
"/api/jobs/**",
"/api/charts/**",
"/api/posts/**",
"/api/processedPosts/**")
"/api/processedPosts/**",
"/api/mongo_file/**")
.hasRole(ROLE_GUEST)
.antMatchers("/api/topics/**",
"/api/jobs/**",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.marble.commons.domain.projections;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;

import org.marble.model.domain.model.Chart;
Expand All @@ -19,6 +20,7 @@ public interface ChartExtendedProjection {
String getName();
String getDescription();
String getType();
String getCustomType();

@Value("#{target.topic != null? target.topic.name : null}")
String getTopicName();
Expand All @@ -28,6 +30,7 @@ public interface ChartExtendedProjection {

BasicDBObject getOptions();
BasicDBObject getData();
ArrayList<String> getFigures();

Date getCreatedAt();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.marble.commons.domain.repository;

import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;

import java.util.List;

import org.marble.model.domain.model.MongoFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import com.mongodb.DBObject;
import com.mongodb.gridfs.GridFSDBFile;
import com.mongodb.gridfs.GridFSFile;

@Repository
public class MongoFileRepository {

Logger log = LoggerFactory.getLogger(getClass());

private final GridFsOperations gridFs;

private final MongoOperations mongo;

private final MongoConverter mongoConverter;

@Autowired
public MongoFileRepository(GridFsOperations gridFs, MongoOperations mongo,
MongoConverter mongoConverter) {
this.gridFs = gridFs;
this.mongo = mongo;
this.mongoConverter = mongoConverter;
}

public MongoFile<DBObject> findById(String id) {
return findBy("_id", id, DBObject.class);
}

public MongoFile<DBObject> findByFilename(String filename) {
return findByFilename(filename, DBObject.class);
}

public <T> MongoFile<T> findByFilename(String filename, Class<T> metadataType) {
return findBy("filename", filename, metadataType);
}

@SuppressWarnings({"unchecked"})
public String[] listFilenames(String locationPattern, Criteria... additionalCriteria) {
if (!StringUtils.hasText(locationPattern)) {
return new String[0];
}

Criteria criteria = null;

criteria = where("filename").is(locationPattern);
if (additionalCriteria != null && additionalCriteria.length != 0) {
criteria = criteria.andOperator(additionalCriteria);
}
Query query = query(criteria);
List<String> filenames =
mongo.getCollection("fs.files").distinct("filename", query.getQueryObject());
return filenames.toArray(new String[0]);
}

public GridFSFile insert(MongoFile<?> file) {
Object metadata = file.getMetadata();
DBObject metadataDbObject = (DBObject) mongoConverter.convertToMongoType(metadata);
return gridFs.store(file.getContent(), file.getFilename(), file.getContentType(), metadataDbObject);
}

public void delete(Query query) {
gridFs.delete(query);
}

protected <T> MongoFile<T> findBy(String property, String value, Class<T> metadataType) {
Query query = query(where(property).is(value)).with(new Sort(Direction.ASC, "uploadDate"));
log.info("Query: {}", query.getQueryObject());
GridFSDBFile gridFsFile = gridFs.findOne(query);
return createMongoFile(gridFsFile, metadataType);
}

@SuppressWarnings("unchecked")
protected <T> MongoFile<T> createMongoFile(GridFSDBFile gridFsFile, Class<T> metadataType) {
if (gridFsFile == null) {
return null;
}
T metadata = null;
if (DBObject.class.equals(metadataType)) {
metadata = (T) gridFsFile.getMetaData();
} else {
metadata = mongoConverter.read(metadataType, gridFsFile.getMetaData());
}
return MongoFile.<T>builder().content(gridFsFile.getInputStream()).id(gridFsFile.getId())
.contentType(gridFsFile.getContentType()).uploadDate(gridFsFile.getUploadDate())
.filename(gridFsFile.getFilename()).metadata(metadata).md5(gridFsFile.getMD5()).build();
}
}
Loading

0 comments on commit 4e1f98c

Please sign in to comment.