Let OverlayModels access the Project at deserialization time

This commit is contained in:
Antonin Delpeuch 2018-11-20 19:11:34 +00:00
parent 99e98a2e78
commit 121661e8eb
2 changed files with 13 additions and 1 deletions

View File

@ -33,7 +33,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.model;
/**
* Overlay models must be serializable and deserializable with Jackson.
* It is possible to have access to the project at deserialization time
* by adding the corresponding parameter to the JSON creator with
* @JacksonInject("project").
*
*/
public interface OverlayModel {
public void onBeforeSave(Project project);

View File

@ -50,6 +50,8 @@ import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.refine.ProjectManager;
import com.google.refine.ProjectMetadata;
import com.google.refine.RefineServlet;
@ -188,6 +190,10 @@ public class Project {
Project project = new Project(id);
int maxCellCount = 0;
ObjectMapper mapper = ParsingUtilities.mapper.copy();
InjectableValues injections = new InjectableValues.Std().addValue("project", project);
mapper.setInjectableValues(injections);
String line;
while ((line = reader.readLine()) != null) {
int equal = line.indexOf('=');