Search in sources :

Example 11 with QueryField

use of fi.otavanopisto.muikku.plugins.material.model.QueryField in project muikku by otavanopisto.

the class QueryFieldChangeListener method onQueryOrganizerFieldUpdate.

public void onQueryOrganizerFieldUpdate(@Observes QueryFieldUpdateEvent event) {
    if (event.getMaterialField().getType().equals("application/vnd.muikku.field.organizer")) {
        QueryField queryField = event.getQueryField();
        List<WorkspaceMaterialField> workspaceMaterialFields = workspaceMaterialFieldController.listWorkspaceMaterialFieldsByQueryField(queryField);
        for (WorkspaceMaterialField workspaceMaterialField : workspaceMaterialFields) {
            workspaceMaterialFieldController.updateWorkspaceMaterialField(workspaceMaterialField, event.getMaterialField(), event.getRemoveAnswers());
        }
    }
}
Also used : QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) WorkspaceMaterialField(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField)

Example 12 with QueryField

use of fi.otavanopisto.muikku.plugins.material.model.QueryField in project muikku by otavanopisto.

the class QueryFieldChangeListener method onQuerySorterFieldUpdate.

public void onQuerySorterFieldUpdate(@Observes QueryFieldUpdateEvent event) {
    if (event.getMaterialField().getType().equals("application/vnd.muikku.field.sorter")) {
        QueryField queryField = event.getQueryField();
        List<WorkspaceMaterialField> workspaceMaterialFields = workspaceMaterialFieldController.listWorkspaceMaterialFieldsByQueryField(queryField);
        for (WorkspaceMaterialField workspaceMaterialField : workspaceMaterialFields) {
            workspaceMaterialFieldController.updateWorkspaceMaterialField(workspaceMaterialField, event.getMaterialField(), event.getRemoveAnswers());
        }
    }
}
Also used : QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) WorkspaceMaterialField(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField)

Example 13 with QueryField

use of fi.otavanopisto.muikku.plugins.material.model.QueryField in project muikku by otavanopisto.

the class QueryFieldChangeListener method onQuerySelectFieldUpdate.

public void onQuerySelectFieldUpdate(@Observes QueryFieldUpdateEvent event) {
    if (event.getMaterialField().getType().equals("application/vnd.muikku.field.select")) {
        QueryField queryField = event.getQueryField();
        List<WorkspaceMaterialField> workspaceMaterialFields = workspaceMaterialFieldController.listWorkspaceMaterialFieldsByQueryField(queryField);
        for (WorkspaceMaterialField workspaceMaterialField : workspaceMaterialFields) {
            workspaceMaterialFieldController.updateWorkspaceMaterialField(workspaceMaterialField, event.getMaterialField(), event.getRemoveAnswers());
        }
    }
}
Also used : QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) WorkspaceMaterialField(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField)

Example 14 with QueryField

use of fi.otavanopisto.muikku.plugins.material.model.QueryField in project muikku by otavanopisto.

the class HtmlMaterialFieldChangeListener method onHtmlMaterialAudioFieldCreated.

// Audio field
public void onHtmlMaterialAudioFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
    if (event.getField().getType().equals("application/vnd.muikku.field.audio")) {
        ObjectMapper objectMapper = new ObjectMapper();
        AudioFieldMeta audioFieldMeta;
        try {
            audioFieldMeta = objectMapper.readValue(event.getField().getContent(), AudioFieldMeta.class);
        } catch (IOException e) {
            throw new MaterialFieldMetaParsingExeption("Could not parse audio field meta", e);
        }
        QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), audioFieldMeta.getName());
        if (queryField != null) {
            throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
        }
        queryAudioFieldController.createQueryAudioField(event.getMaterial(), audioFieldMeta.getName());
    }
}
Also used : QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) IOException(java.io.IOException) AudioFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.AudioFieldMeta) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 15 with QueryField

use of fi.otavanopisto.muikku.plugins.material.model.QueryField in project muikku by otavanopisto.

the class HtmlMaterialFieldChangeListener method onHtmlMaterialConnectFieldCreated.

// Connect field
public void onHtmlMaterialConnectFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
    if (event.getField().getType().equals("application/vnd.muikku.field.connect")) {
        ObjectMapper objectMapper = new ObjectMapper();
        ConnectFieldMeta connectFieldMeta;
        try {
            connectFieldMeta = objectMapper.readValue(event.getField().getContent(), ConnectFieldMeta.class);
        } catch (IOException e) {
            throw new MaterialFieldMetaParsingExeption("Could not parse connect field meta", e);
        }
        QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), connectFieldMeta.getName());
        if (queryField != null) {
            throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
        }
        QueryConnectField field = queryConnectFieldController.createQueryConnectField(event.getMaterial(), connectFieldMeta.getName());
        Map<String, QueryConnectFieldTerm> terms = new HashMap<String, QueryConnectFieldTerm>();
        Map<String, QueryConnectFieldCounterpart> counterparts = new HashMap<String, QueryConnectFieldCounterpart>();
        for (ConnectFieldOptionMeta option : connectFieldMeta.getFields()) {
            terms.put(option.getName(), queryConnectFieldController.createConnectFieldTerm(field, option.getName(), option.getText(), null));
        }
        for (ConnectFieldOptionMeta option : connectFieldMeta.getCounterparts()) {
            counterparts.put(option.getName(), queryConnectFieldController.createConnectFieldCounterpart(field, option.getName(), option.getText()));
        }
        for (ConnectFieldConnectionMeta connection : connectFieldMeta.getConnections()) {
            terms.get(connection.getField()).setCounterpart(counterparts.get(connection.getCounterpart()));
        }
    }
}
Also used : ConnectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta) HashMap(java.util.HashMap) QueryConnectFieldCounterpart(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart) ConnectFieldConnectionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldConnectionMeta) IOException(java.io.IOException) QueryConnectFieldTerm(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm) ConnectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldOptionMeta) QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) QueryConnectField(fi.otavanopisto.muikku.plugins.material.model.QueryConnectField)

Aggregations

QueryField (fi.otavanopisto.muikku.plugins.material.model.QueryField)17 IOException (java.io.IOException)9 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 WorkspaceMaterialField (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField)6 MultiSelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta)2 MultiSelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 AudioFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.AudioFieldMeta)1 ConnectFieldConnectionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldConnectionMeta)1 ConnectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta)1 ConnectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldOptionMeta)1 FileFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.FileFieldMeta)1 OrganizerFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.OrganizerFieldMeta)1 SelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldMeta)1 SelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta)1 SorterFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SorterFieldMeta)1 TextFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1