diff --git a/src/main/java/org/wikitolearn/wikirating/controller/MaintenanceController.java b/src/main/java/org/wikitolearn/wikirating/controller/MaintenanceController.java index 209e8e7..0f08a60 100644 --- a/src/main/java/org/wikitolearn/wikirating/controller/MaintenanceController.java +++ b/src/main/java/org/wikitolearn/wikirating/controller/MaintenanceController.java @@ -1,197 +1,199 @@ /** * */ package org.wikitolearn.wikirating.controller; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.DefaultPropertiesPersister; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -//import org.wikitolearn.wikirating.model.Process; -import org.wikitolearn.wikirating.service.PageService; -import org.wikitolearn.wikirating.service.RevisionService; -import org.wikitolearn.wikirating.service.UserService; -//import org.wikitolearn.wikirating.util.MediaWikiApiUtils; -//import org.wikitolearn.wikirating.util.enums.ProcessResult; -//import org.wikitolearn.wikirating.util.enums.ProcessType; +import org.wikitolearn.wikirating.model.Process; +import org.wikitolearn.wikirating.service.*; +import org.wikitolearn.wikirating.util.enums.ProcessStatus; +import org.wikitolearn.wikirating.util.enums.ProcessType; /** * * @author aletundo * */ @RestController public class MaintenanceController { private static final Logger LOG = LoggerFactory.getLogger(MaintenanceController.class); @Autowired private PageService pageService; @Autowired private UserService userService; @Autowired private RevisionService revisionService; + @Autowired + private ProcessService processService; + @Autowired + private MetadataService metadataService; @Value("#{'${mediawiki.langs}'.split(',')}") private List langs; @Value("${mediawiki.protocol}") private String protocol; @Value("${mediawiki.api.url}") private String apiUrl; /** * Secured endpoint to enable or disable read only mode. When read only mode * is enabled only GET requests are allowed. To change this behavior @see * org.wikitolearn.wikirating.wikirating.filter.MaintenanceFilter. * * @param active * String requested parameter that toggle the re. Binary values * are accepted. * @return a JSON object with the response */ @RequestMapping(value = "${maintenance.readonlymode.uri}", method = RequestMethod.POST, produces = "application/json") public String toggleReadOnlyMode(@RequestParam(value = "active") String active) { JSONObject response = new JSONObject(); int mode = Integer.parseInt(active); try { if (mode == 0) { response.put("status", "success"); response.put("message", "Application is live now."); // Delete maintenance lock file if it exists File f = new File("maintenance.lock"); if (f.exists()) { f.delete(); LOG.debug("Deleted maintenance lock file."); } LOG.info("Application is live now."); } else if (mode == 1) { try { response.put("status", "success"); response.put("message", "Application is in maintenance mode now."); // Create maintenance lock file with a maintenance.active // property setted to true Properties props = new Properties(); props.setProperty("maintenance.active", "true"); File lockFile = new File("maintenance.lock"); OutputStream out = new FileOutputStream(lockFile); DefaultPropertiesPersister p = new DefaultPropertiesPersister(); p.store(props, out, "Maintenance mode lock file"); LOG.debug("Created maintenance lock file."); LOG.info("Application is in maintenance mode now."); } catch (Exception e) { LOG.error("Something went wrong. {}", e.getMessage()); } } else { // The active parameter value is not supported response.put("status", "error"); response.put("message", "Parameter value not supported"); } } catch (JSONException e) { LOG.error("Something went wrong using JSON API. {}", e.getMessage()); } return response.toString(); } /** * Secured endpoint that handles initialization request for the given * language - * - * @param lang + * * @return true if the initialization is completed without errors, false * otherwise */ @RequestMapping(value = "${maintenance.init.uri}", method = RequestMethod.POST, produces = "application/json") public boolean initialize() { + // Initialize Metadata service + metadataService.initMetadata(); // Starting a new Process - // Process initializeProcess = new Process(ProcessType.INIT); + Process initializeProcess = processService.createNewProcess(ProcessType.INIT); CompletableFuture initFuture = CompletableFuture .allOf(buildUsersAndPagesFutersList().toArray(new CompletableFuture[langs.size() + 1])) .thenCompose(result -> CompletableFuture .allOf(buildRevisionsFuturesList().toArray(new CompletableFuture[langs.size()]))) .thenCompose(result -> userService.setAllUsersAuthorship()); /* * CompletableFuture parallelInsertions = * CompletableFuture.allOf(pageService.addAllPages(lang, url), * userService.addAllUsers(url)) .thenCompose(result -> * revisionService.addAllRevisions(lang, url)) .thenCompose(result -> * userService.setAllUsersAuthorship()); */ try { - /* - * boolean result = parallelInsertions.get(); //saving the result of - * the process if (result){ - * initializeProcess.setProcessResult(ProcessResult.DONE); }else{ - * initializeProcess.setProcessResult(ProcessResult.ERROR); } - * //metadataDAO.addProcess(initializeProcess); return result; - */ - return initFuture.get(); + boolean result = initFuture.get(); + //saving the result of the process + if (result){ + processService.closeCurrentProcess(ProcessStatus.DONE); + }else{ + processService.closeCurrentProcess(ProcessStatus.EXCEPTION); + } + return result; } catch (InterruptedException | ExecutionException e) { LOG.error("Something went wrong. {}", e.getMessage()); return false; } } /** * */ @RequestMapping(value = "${maintenance.wipe.uri}", method = RequestMethod.DELETE, produces = "application/json") public void wipeDatabase() { // TODO } /** * Build a list of CompletableFuture. The elements are the fetches of pages' * revisions from each domain language. * * @return a list of CompletableFuture */ private List> buildRevisionsFuturesList() { List> parallelRevisionsFutures = new ArrayList<>(); // Add revisions fetch for each domain language for (String lang : langs) { String url = protocol + lang + "." + apiUrl; parallelRevisionsFutures.add(revisionService.addAllRevisions(lang, url)); } return parallelRevisionsFutures; } /** * Build a list of CompletableFuture. The first one is the fetch of the * users from the first domain in mediawiki.langs list. The rest of the * elements are the fetches of the pages for each language. This * implementation assumes that the users are shared among domains. * * @return a list of CompletableFuture */ private List> buildUsersAndPagesFutersList() { List> usersAndPagesInsertion = new ArrayList<>(); // Add users fetch as fist operation usersAndPagesInsertion.add(userService.addAllUsers(protocol + langs.get(0) + "." + apiUrl)); // Add pages fetch for each domain language for (String lang : langs) { String url = protocol + lang + "." + apiUrl; usersAndPagesInsertion.add(pageService.addAllPages(lang, url)); } return usersAndPagesInsertion; } } diff --git a/src/main/java/org/wikitolearn/wikirating/model/Metadata.java b/src/main/java/org/wikitolearn/wikirating/model/Metadata.java index 7b52c42..fd0c66f 100644 --- a/src/main/java/org/wikitolearn/wikirating/model/Metadata.java +++ b/src/main/java/org/wikitolearn/wikirating/model/Metadata.java @@ -1,60 +1,44 @@ package org.wikitolearn.wikirating.model; import org.neo4j.ogm.annotation.GraphId; import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.Relationship; +import org.wikitolearn.wikirating.util.enums.MetadataType; /** * This entity represents the root of the chain of processes. * It is used also to store some global stats. * Created by valsdav on 24/03/17. */ @NodeEntity(label="Metadata") public class Metadata { - @GraphId private Long id; - @Relationship(type="LAST_PROCESS", direction = Relationship.OUTGOING) - private Process lastProcess; - private int currentnumberOfPages; - private int numberOfRevisions; - private int numberOfUsers; - - public Metadata() {} - - public Metadata(int currentnumberOfPages, int numberOfRevisions, int numberOfUsers) { - this.currentnumberOfPages = currentnumberOfPages; - this.numberOfRevisions = numberOfRevisions; - this.numberOfUsers = numberOfUsers; - } - - public Process getLastProcess() { - return lastProcess; - } + @GraphId + private Long id; + @Relationship(type = "LAST", direction = Relationship.OUTGOING) + private Process lastItem; + private MetadataType type; - public void setLastProcess(Process lastProcess) { - this.lastProcess = lastProcess; + public Metadata() { } - public int getCurrentnumberOfPages() { - return currentnumberOfPages; + public Metadata(MetadataType type){ + this.type = type; } - public void setCurrentnumberOfPages(int currentnumberOfPages) { - this.currentnumberOfPages = currentnumberOfPages; + public Process getLastItem() { + return lastItem; } - public int getNumberOfRevisions() { - return numberOfRevisions; + public void setLastItem(Process lastItem) { + this.lastItem = lastItem; } - public void setNumberOfRevisions(int numberOfRevisions) { - this.numberOfRevisions = numberOfRevisions; + public MetadataType getType() { + return type; } - public int getNumberOfUsers() { - return numberOfUsers; - } - - public void setNumberOfUsers(int numberOfUsers) { - this.numberOfUsers = numberOfUsers; + public void setType(MetadataType type) { + this.type = type; } } + diff --git a/src/main/java/org/wikitolearn/wikirating/model/Process.java b/src/main/java/org/wikitolearn/wikirating/model/Process.java index e1ae056..564ca69 100644 --- a/src/main/java/org/wikitolearn/wikirating/model/Process.java +++ b/src/main/java/org/wikitolearn/wikirating/model/Process.java @@ -1,85 +1,103 @@ package org.wikitolearn.wikirating.model; import org.neo4j.ogm.annotation.GraphId; +import org.neo4j.ogm.annotation.Index; import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.Relationship; import org.neo4j.ogm.annotation.typeconversion.DateLong; -import org.wikitolearn.wikirating.util.enums.ProcessResult; +import org.wikitolearn.wikirating.util.enums.ProcessStatus; import org.wikitolearn.wikirating.util.enums.ProcessType; import java.util.Date; +import java.util.UUID; /** * This class represents a Process happened in the engine. * It has a definite type and can have different results. It is saved in the DB * as a Process vertex. * @author aletundo * @author valsdav */ @NodeEntity( label = "Process") public class Process { @GraphId private Long graphId; + @Index(unique = true, primary = true) + private String processId; private ProcessType processType; - private ProcessResult processResult; + private ProcessStatus processStatus; @Relationship(type="PREVIOUS_PROCESS", direction = Relationship.OUTGOING) private Process previousProcess; @DateLong private Date beginOfProcess; @DateLong private Date endOfProcess; public Process() {} - public Process( ProcessType processType, ProcessResult processResult, Date beginOfProcess, Date endOfProcess) { + public Process(String processId, ProcessType processType, + ProcessStatus processStatus, Date beginOfProcess, Date endOfProcess) { + this.processId = processId; this.processType = processType; - this.processResult = processResult; + this.processStatus = processStatus; this.beginOfProcess = beginOfProcess; this.endOfProcess = endOfProcess; } public Process(ProcessType processType){ + this.processId = UUID.randomUUID().toString(); this.processType = processType; - this.processResult = ProcessResult.ONGOING; + this.processStatus = ProcessStatus.ONGOING; this.beginOfProcess = new Date(); } public ProcessType getProcessType() { return processType; } public void setProcessType(ProcessType processType) { this.processType = processType; } - public ProcessResult getProcessResult() { - return processResult; + public ProcessStatus getProcessStatus() { + return processStatus; } - public void setProcessResult(ProcessResult processResult) { - this.processResult = processResult; + public void setProcessStatus(ProcessStatus processStatus) { + this.processStatus = processStatus; } public Process getPreviousProcess() { return previousProcess; } public void setPreviousProcess(Process previousProcess) { this.previousProcess = previousProcess; } public Date getBeginOfProcess() { return beginOfProcess; } public void setBeginOfProcess(Date beginOfProcess) { this.beginOfProcess = beginOfProcess; } public Date getEndOfProcess() { return endOfProcess; } public void setEndOfProcess(Date endOfProcess) { this.endOfProcess = endOfProcess; } + + @Override + public String toString() { + return "Process[" + + "processId='" + processId + '\'' + + ", processType=" + processType + + ", processStatus=" + processStatus + + ", beginOfProcess=" + beginOfProcess + + ", endOfProcess=" + endOfProcess + + ']'; + } } diff --git a/src/main/java/org/wikitolearn/wikirating/model/Revision.java b/src/main/java/org/wikitolearn/wikirating/model/Revision.java index 3846b42..a913cb2 100644 --- a/src/main/java/org/wikitolearn/wikirating/model/Revision.java +++ b/src/main/java/org/wikitolearn/wikirating/model/Revision.java @@ -1,367 +1,372 @@ package org.wikitolearn.wikirating.model; import org.neo4j.ogm.annotation.GraphId; import org.neo4j.ogm.annotation.Index; import org.neo4j.ogm.annotation.NodeEntity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.neo4j.ogm.annotation.Relationship; import org.neo4j.ogm.annotation.typeconversion.DateLong; import java.util.Date; import java.util.Set; /** * This class handles the data of the Revision of a page. * Created by valsdav on 14/03/17. */ @JsonIgnoreProperties(ignoreUnknown = true) @NodeEntity( label = "Revision" ) public class Revision { @GraphId private Long graphId; private int revid; private String lang; private int userid; private int parentid; @DateLong private Date timestamp; private long length; private double changeCoefficient; private double currentMeanVote; private double currentVotesReliability; private double currentNormalisesVotesReliability; private double totalMeanVote; private double totalVotesReliability; private double totalNormalisesVotesReliability; private boolean validated; @Index(unique = true, primary=true) private String langRevId; @Relationship(type="PREVIOUS_REVISION", direction = Relationship.OUTGOING) private Revision previousRevision; @Relationship(type="VOTE", direction = Relationship.INCOMING) private Set votes; @Relationship( type="AUTHOR", direction = Relationship.INCOMING) private User author; /** * */ public Revision() {} /** * @param revid * @param userid * @param parentid * @param length * @param changeCoefficient * @param currentMeanVote * @param currentVotesReliability * @param currentNormalisesVotesReliability * @param totalMeanVote * @param totalVotesReliability * @param totalNormalisesVotesReliability * @param validated * @param lang * @param timestamp */ public Revision(int revid, int userid, int parentid, long length, double changeCoefficient, double currentMeanVote, double currentVotesReliability, double currentNormalisesVotesReliability, double totalMeanVote, double totalVotesReliability, double totalNormalisesVotesReliability, boolean validated, String lang, Date timestamp) { this.revid = revid; this.userid = userid; this.parentid = parentid; this.length = length; this.changeCoefficient = changeCoefficient; this.currentMeanVote = currentMeanVote; this.currentVotesReliability = currentVotesReliability; this.currentNormalisesVotesReliability = currentNormalisesVotesReliability; this.totalMeanVote = totalMeanVote; this.totalVotesReliability = totalVotesReliability; this.totalNormalisesVotesReliability = totalNormalisesVotesReliability; this.validated = validated; this.lang = lang; this.timestamp = timestamp; } /** * @return the revid */ public int getRevid() { return revid; } /** * @param revid the revid to set */ public void setRevid(int revid) { this.revid = revid; } /** * @return the userid */ public int getUserid() { return userid; } /** * @param userid the userid to set */ public void setUserid(int userid) { this.userid = userid; } /** * @return the parentid */ public int getParentid() { return parentid; } /** * @param parentid the parentid to set */ public void setParentid(int parentid) { this.parentid = parentid; } /** * @return the length */ public long getLength() { return length; } /** * @param length the length to set */ public void setLength(long length) { this.length = length; } /** * @return the changeCoefficient */ public double getChangeCoefficient() { return changeCoefficient; } /** * @param changeCoefficient the changeCoefficient to set */ public void setChangeCoefficient(double changeCoefficient) { this.changeCoefficient = changeCoefficient; } /** * @return the currentMeanVote */ public double getCurrentMeanVote() { return currentMeanVote; } /** * @param currentMeanVote the currentMeanVote to set */ public void setCurrentMeanVote(double currentMeanVote) { this.currentMeanVote = currentMeanVote; } /** * @return the currentVotesReliability */ public double getCurrentVotesReliability() { return currentVotesReliability; } /** * @param currentVotesReliability the currentVotesReliability to set */ public void setCurrentVotesReliability(double currentVotesReliability) { this.currentVotesReliability = currentVotesReliability; } /** * @return the currentNormalisesVotesReliability */ public double getCurrentNormalisesVotesReliability() { return currentNormalisesVotesReliability; } /** * @param currentNormalisesVotesReliability the currentNormalisesVotesReliability to set */ public void setCurrentNormalisesVotesReliability(double currentNormalisesVotesReliability) { this.currentNormalisesVotesReliability = currentNormalisesVotesReliability; } /** * @return the totalMeanVote */ public double getTotalMeanVote() { return totalMeanVote; } /** * @param totalMeanVote the totalMeanVote to set */ public void setTotalMeanVote(double totalMeanVote) { this.totalMeanVote = totalMeanVote; } /** * @return the totalVotesReliability */ public double getTotalVotesReliability() { return totalVotesReliability; } /** * @param totalVotesReliability the totalVotesReliability to set */ public void setTotalVotesReliability(double totalVotesReliability) { this.totalVotesReliability = totalVotesReliability; } /** * @return the totalNormalisesVotesReliability */ public double getTotalNormalisesVotesReliability() { return totalNormalisesVotesReliability; } /** * @param totalNormalisesVotesReliability the totalNormalisesVotesReliability to set */ public void setTotalNormalisesVotesReliability(double totalNormalisesVotesReliability) { this.totalNormalisesVotesReliability = totalNormalisesVotesReliability; } /** * @return the validated */ public boolean isValidated() { return validated; } /** * @param validated the validated to set */ public void setValidated(boolean validated) { this.validated = validated; } /** * @return the lang */ public String getLang() { return lang; } /** * @param lang the lang to set */ public void setLang(String lang) { this.lang = lang; } /** * @return the langRevId */ public String getLangRevId() { return langRevId; } /** * @param langRevId the langRevId to set */ public void setLangRevId(String langRevId) { this.langRevId = langRevId; } /** * @return the graphId */ public Long getGraphId() { return graphId; } /** * @param graphId the graphId to set */ public void setGraphId(Long graphId) { this.graphId = graphId; } /** * @return the timestamp */ public Date getTimestamp() { return timestamp; } /** * @param timestamp the timestamp to set */ public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } /** * @return the previousRevision */ public Revision getPreviousRevision() { return previousRevision; } /** * @param previousRevision the previousRevision to set */ public void setPreviousRevision(Revision previousRevision) { this.previousRevision = previousRevision; } /** * @return the votes */ public Set getVotes() { return votes; } /** * @param votes the votes to set */ public void setVotes(Set votes) { this.votes = votes; } /** * @return the author */ public User getAuthor() { return author; } /** * @param author the author to set */ public void setAuthor(User author) { this.author = author; } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { - return "Revision [graphId=" + graphId + ", revid=" + revid + ", lang=" + lang + ", userid=" + userid - + ", parentid=" + parentid + ", timestamp=" + timestamp + ", length=" + length + ", changeCoefficient=" - + changeCoefficient + ", currentMeanVote=" + currentMeanVote + ", currentVotesReliability=" - + currentVotesReliability + ", currentNormalisesVotesReliability=" + currentNormalisesVotesReliability - + ", totalMeanVote=" + totalMeanVote + ", totalVotesReliability=" + totalVotesReliability - + ", totalNormalisesVotesReliability=" + totalNormalisesVotesReliability + ", validated=" + validated - + ", langRevId=" + langRevId + ", previousRevision=" + previousRevision + ", votes=" + votes - + ", author=" + author + "]"; + return "Revision{" + + "graphId=" + graphId + + ", revid=" + revid + + ", lang='" + lang + '\'' + + ", userid=" + userid + + ", parentid=" + parentid + + ", timestamp=" + timestamp + + ", length=" + length + + ", changeCoefficient=" + changeCoefficient + + ", validated=" + validated + + ", langRevId='" + langRevId + '\'' + + ", author=" + author + + '}'; } } \ No newline at end of file diff --git a/src/main/java/org/wikitolearn/wikirating/repository/MetadataRepository.java b/src/main/java/org/wikitolearn/wikirating/repository/MetadataRepository.java index 1418aeb..ce82409 100644 --- a/src/main/java/org/wikitolearn/wikirating/repository/MetadataRepository.java +++ b/src/main/java/org/wikitolearn/wikirating/repository/MetadataRepository.java @@ -1,10 +1,14 @@ package org.wikitolearn.wikirating.repository; import org.springframework.data.neo4j.repository.GraphRepository; import org.wikitolearn.wikirating.model.Metadata; +import org.wikitolearn.wikirating.util.enums.MetadataType; /** * Created by valsdav on 24/03/17. */ public interface MetadataRepository extends GraphRepository{ + + Metadata getMetadataByType(MetadataType type); + } diff --git a/src/main/java/org/wikitolearn/wikirating/repository/ProcessRepository.java b/src/main/java/org/wikitolearn/wikirating/repository/ProcessRepository.java index 12b9e58..e99ca09 100644 --- a/src/main/java/org/wikitolearn/wikirating/repository/ProcessRepository.java +++ b/src/main/java/org/wikitolearn/wikirating/repository/ProcessRepository.java @@ -1,15 +1,19 @@ /** * */ package org.wikitolearn.wikirating.repository; +import org.springframework.data.neo4j.annotation.Query; import org.springframework.data.neo4j.repository.GraphRepository; import org.wikitolearn.wikirating.model.Process; +import org.wikitolearn.wikirating.util.enums.MetadataType; /** * @author aletundo * */ public interface ProcessRepository extends GraphRepository { - + + @Query("MATCH (p:Process)<-[LAST_PROCESS]-(m:Metadata {type:'PROCESSES'}) RETURN p") + public Process getLastProcess(); } diff --git a/src/main/java/org/wikitolearn/wikirating/service/MetadataService.java b/src/main/java/org/wikitolearn/wikirating/service/MetadataService.java new file mode 100644 index 0000000..451f0b3 --- /dev/null +++ b/src/main/java/org/wikitolearn/wikirating/service/MetadataService.java @@ -0,0 +1,44 @@ +package org.wikitolearn.wikirating.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.wikitolearn.wikirating.model.Metadata; +import org.wikitolearn.wikirating.model.Process; +import org.wikitolearn.wikirating.repository.MetadataRepository; +import org.wikitolearn.wikirating.repository.ProcessRepository; +import org.wikitolearn.wikirating.service.mediawiki.PageMediaWikiService; +import org.wikitolearn.wikirating.util.enums.MetadataType; + +/** + * This service manages the addition of information about Metadata. + * Created by valsdav on 29/03/17. + */ +@Service +public class MetadataService { + private static final Logger LOG = LoggerFactory.getLogger(PageService.class); + @Autowired + private PageMediaWikiService pageMediaWikiService; + @Autowired + private MetadataRepository metadataRepository; + @Autowired + private ProcessRepository processRepository; + + public void initMetadata(){ + Metadata metadataProcesses = new Metadata(MetadataType.PROCESSES); + Metadata metadataStats = new Metadata(MetadataType.STATS); + metadataRepository.save(metadataProcesses); + metadataRepository.save(metadataStats); + } + + public boolean addProcess(Process process){ + Metadata metadata = metadataRepository.getMetadataByType(MetadataType.PROCESSES); + //Creating the new process node of the chain + process.setPreviousProcess(metadata.getLastItem()); + metadata.setLastItem(process); + metadataRepository.save(metadata); + LOG.info("Process {} inserted ", process); + return true; + } +} diff --git a/src/main/java/org/wikitolearn/wikirating/service/ProcessService.java b/src/main/java/org/wikitolearn/wikirating/service/ProcessService.java new file mode 100644 index 0000000..4ad3bf0 --- /dev/null +++ b/src/main/java/org/wikitolearn/wikirating/service/ProcessService.java @@ -0,0 +1,37 @@ +package org.wikitolearn.wikirating.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.wikitolearn.wikirating.model.Process; +import org.wikitolearn.wikirating.repository.ProcessRepository; +import org.wikitolearn.wikirating.util.enums.ProcessStatus; +import org.wikitolearn.wikirating.util.enums.ProcessType; + +import java.util.Date; + +/** + * Created by valsdav on 29/03/17. + */ +@Service +public class ProcessService { + @Autowired + private MetadataService metadataService; + @Autowired + private ProcessRepository processRepository; + + public Process createNewProcess(ProcessType type){ + Process proc = new Process(type); + metadataService.addProcess(proc); + processRepository.save(proc); + return proc; + } + + public Process closeCurrentProcess(ProcessStatus status){ + Process currentProcess = processRepository.getLastProcess(); + currentProcess.setProcessStatus(status); + currentProcess.setEndOfProcess(new Date()); + processRepository.save(currentProcess); + return currentProcess; + } + +} diff --git a/src/main/java/org/wikitolearn/wikirating/util/enums/MetadataType.java b/src/main/java/org/wikitolearn/wikirating/util/enums/MetadataType.java new file mode 100644 index 0000000..59489cb --- /dev/null +++ b/src/main/java/org/wikitolearn/wikirating/util/enums/MetadataType.java @@ -0,0 +1,8 @@ +package org.wikitolearn.wikirating.util.enums; + +/** + * Created by valsdav on 29/03/17. + */ +public enum MetadataType { + PROCESSES, STATS; +} diff --git a/src/main/java/org/wikitolearn/wikirating/util/enums/ProcessResult.java b/src/main/java/org/wikitolearn/wikirating/util/enums/ProcessStatus.java similarity index 82% rename from src/main/java/org/wikitolearn/wikirating/util/enums/ProcessResult.java rename to src/main/java/org/wikitolearn/wikirating/util/enums/ProcessStatus.java index 4ca4dea..cfb6748 100644 --- a/src/main/java/org/wikitolearn/wikirating/util/enums/ProcessResult.java +++ b/src/main/java/org/wikitolearn/wikirating/util/enums/ProcessStatus.java @@ -1,8 +1,8 @@ package org.wikitolearn.wikirating.util.enums; /** * Created by valsdav on 21/03/17. */ -public enum ProcessResult { +public enum ProcessStatus { DONE, ERROR, EXCEPTION, ONGOING; }