Skip to content
Snippets Groups Projects
Commit 60ffb118 authored by Thomas's avatar Thomas
Browse files

Deploy scripts, fixed db filler & admin endpoints

parent b095bae3
No related branches found
No related tags found
No related merge requests found
FROM alpine-java:base
MAINTAINER gltron
COPY mozen/target/mozen-0.0.1-SNAPSHOT.jar /home/mozen-0.0.1-SNAPSHOT.jar
CMD ["java","-jar","/home/mozen-0.0.1-SNAPSHOT.jar"]
EXPOSE 8181
\ No newline at end of file
docker build . -t gltron/mozen
docker run -d -p 8007:8181 gltron/mozen
\ No newline at end of file
......@@ -35,15 +35,14 @@ public class WebSecurity extends WebSecurityConfigurerAdapter{
.and()
.authorizeRequests()
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.antMatchers(HttpMethod.POST, "/user/signup").permitAll()
.antMatchers(HttpMethod.GET, "/search").permitAll()
.antMatchers(HttpMethod.GET, "/models").permitAll()
.antMatchers(HttpMethod.GET, "/models/tags").permitAll()
.antMatchers(HttpMethod.GET, "/models/download").permitAll()
.antMatchers(HttpMethod.GET, "/models/downloadLayer").permitAll()
.antMatchers(HttpMethod.GET, "/user/list").hasRole("ADMIN")
.antMatchers(HttpMethod.GET, "/model/list").hasRole("ADMIN")
.anyRequest().authenticated()
// .anyRequest().authenticated()
.and()
.addFilter(new JwtAuthenticationFilter(authenticationManager()))
.addFilter(new JwtAuthorizationFilter(authenticationManager()))
......
......@@ -9,6 +9,7 @@ import mozen.messages.TagMessage;
import mozen.model.CustomLayer;
import mozen.model.Model;
import mozen.messages.SearchResult;
import mozen.messages.TagCategoryMessage;
import mozen.model.TagCategory;
import mozen.model.User;
......@@ -22,6 +23,10 @@ public interface IModelManager {
void removeLayer(long id, User user) throws Exception;
void addTag(TagMessage message);
void removeTag(long id);
void addCategory(TagCategoryMessage message);
void removeCategory(long id);
Model getModel(long id);
Collection<Model> getModels();
......
......@@ -19,6 +19,7 @@ import mozen.model.CustomLayer;
import mozen.model.Model;
import mozen.model.Role;
import mozen.messages.SearchResult;
import mozen.messages.TagCategoryMessage;
import mozen.model.Tag;
import mozen.model.TagCategory;
import mozen.model.User;
......@@ -42,7 +43,8 @@ public class ModelManager implements IModelManager {
public Long addModel(ModelMessage message, User user) throws Exception {
Model model = new Model();
System.err.println("[MODEL MANAGER] add model n:"+message.getName()+" sd:"+message.getShortDescription()+" ld:"+message.getLongDescription()+" t:"+message.getTags()+" l:"+message.getCustomLayers());
System.err.println("[MODEL MANAGER] add model n:" + message.getName() + " sd:" + message.getShortDescription()
+ " ld:" + message.getLongDescription() + " t:" + message.getTags() + " l:" + message.getCustomLayers());
model.setName(message.getName());
model.setShortDescription(message.getShortDescription());
......@@ -190,21 +192,24 @@ public class ModelManager implements IModelManager {
}
private boolean isLayerAuthor(CustomLayer layer, User user) {
if (user.getRole() == Role.ROLE_ADMIN) return true;
if (user.getRole() == Role.ROLE_ADMIN)
return true;
return layer.getModel().getAuthor() == user;
}
private boolean isModelAuthor(Model model, User user) {
if (user.getRole() == Role.ROLE_ADMIN) return true;
if (user.getRole() == Role.ROLE_ADMIN)
return true;
return model.getAuthor() == user;
}
@Override
public SearchResult findModelWithTags(String name, int page, int size, String sort, Collection<String> tagsName) {
System.err.println("[MODEL MANAGER] search with tags n:"+name+" p:"+page+" si:"+size+" so:"+sort+" t:"+tagsName);
System.err.println(
"[MODEL MANAGER] search with tags n:" + name + " p:" + page + " si:" + size + " so:" + sort + " t:" + tagsName);
Pageable paging = PageRequest.of(page - 1, size, Sort.by(sort));
Collection<Tag> tags = tagRepo.findByNameIn(tagsName);
Page<Model> resultPage = modelRepo.findByNameContainingIgnoreCaseAndTagsIn(name, tags, paging);
Page<Model> resultPage = modelRepo.findDistinctByNameContainingIgnoreCaseAndTagsIn(name, tags, paging);
System.err.println("[MODEL MANAGER] search result " + resultPage.getTotalElements());
......@@ -232,4 +237,21 @@ public class ModelManager implements IModelManager {
return layerRepo.findById(id).get();
}
@Override
public void removeTag(long id) {
tagRepo.deleteById(id);
}
@Override
public void removeCategory(long id) {
tagCategoryRepo.deleteById(id);
}
@Override
public void addCategory(TagCategoryMessage message) {
TagCategory category = new TagCategory();
category.setName(message.getName());
tagCategoryRepo.save(category);
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ public interface ModelRepository extends PagingAndSortingRepository<Model, Long>
Collection<Model> findAll();
Page<Model> findByNameContainingIgnoreCase(String name, Pageable pageable);
Page<Model> findByNameContainingIgnoreCaseAndTagsIn(String name, Collection<Tag> tags, Pageable pageable);
Page<Model> findDistinctByNameContainingIgnoreCaseAndTagsIn(String name, Collection<Tag> tags, Pageable pageable);
// @Query("SELECT m FROM Model m WHERE m.name LIKE :name AND m.tags CONTAINS (SELECT t FROM Tag WHERE t.name IN :tags)") <- enfer absolu
// Page<Model> findByNameContainingIgnoreCaseTags(@Param("name") String name, @Param("tags") Collection<String> tags, Pageable pageable);
......
package mozen.messages;
import java.io.Serializable;
public class TagCategoryMessage implements Serializable{
private static final long serialVersionUID = 1L;
private String name;
public TagCategoryMessage() {
}
public TagCategoryMessage(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
\ No newline at end of file
package mozen.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
......@@ -11,6 +10,8 @@ import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -42,7 +43,7 @@ public class DatabaseFiller {
@Transactional
public void fillDB() {
System.err.println("FILLING DB");
System.err.println("[DB FILLER] Begin");
User u1 = new User();
u1.setEmail("user1@email.com");
u1.setPassword(bCryptPasswordEncoder.encode("1234"));
......@@ -69,7 +70,7 @@ public class DatabaseFiller {
m1.setVotes(0);
m1.setAdded(new Date());
m1.setLastModified(new Date());
m1.setTags(tagLoader("tags.txt"));
m1.setTags(tagLoader());
Set<CustomLayer> m1layers = new HashSet<CustomLayer>();
CustomLayer l1 = new CustomLayer();
......@@ -86,17 +87,19 @@ public class DatabaseFiller {
userRepo.save(u2);
userRepo.save(admin);
System.err.println("[DB FILLER] Users added");
modelRepo.save(m1);
System.err.println("[DB FILLER] Model added");
}
Set<Tag> tagLoader(String filePath) {
Set<Tag> tagLoader() {
Set<Tag> tags = new HashSet<Tag>();
File file = new File(filePath);
FileReader fr;
Resource resource = new ClassPathResource("tags.txt");
try {
fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println("[DB FILLER] adding category "+line);
......@@ -114,9 +117,9 @@ public class DatabaseFiller {
line = br.readLine();
}
}
fr.close();
System.err.println("[DB FILLER] Tags added");
} catch (IOException e) {
e.printStackTrace();
System.err.println("[DB FILLER] Tags failed");
}
return tags;
......
......@@ -25,6 +25,7 @@ import mozen.model.CustomLayer;
import mozen.model.Model;
import mozen.messages.ModelMessage;
import mozen.messages.ResponseMessage;
import mozen.messages.TagCategoryMessage;
import mozen.messages.TagMessage;
import mozen.model.TagCategory;
import mozen.model.User;
......@@ -132,6 +133,24 @@ public class ModelController {
return ResponseEntity.ok().build();
}
@DeleteMapping("/tags")
public ResponseEntity<ResponseMessage> deleteTag(@RequestParam(value = "id", required = true) Long id) {
modelManager.removeTag(id);
return ResponseEntity.ok().build();
}
@PostMapping("/category")
public ResponseEntity<ResponseMessage> addCategory(@RequestBody @Valid TagCategoryMessage message) {
modelManager.addCategory(message);
return ResponseEntity.ok().build();
}
@DeleteMapping("/category")
public ResponseEntity<ResponseMessage> deleteCategory(@RequestParam(value = "id", required = true) Long id) {
modelManager.removeCategory(id);
return ResponseEntity.ok().build();
}
@PostMapping("/upload")
public ResponseEntity<ResponseMessage> uploadModelFile(@RequestParam("file") MultipartFile file, @RequestParam(value = "id", required = true) Long id) {
ResponseMessage response = new ResponseMessage(false, "");
......
File moved
git clone https://gitlab.lis-lab.fr/thomas.blanc/ter-modelzoo-frontend.git
cd ter-modelzoo-frontend
npm install
npm run build
mv dist/* ../mozen/src/main/resources/public/
cd ../mozen
mvn package
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment