use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm in project muikku by otavanopisto.
the class QueryConnectFieldTermDAO method findByFieldAndName.
public QueryConnectFieldTerm findByFieldAndName(QueryConnectField field, String name) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<QueryConnectFieldTerm> criteria = criteriaBuilder.createQuery(QueryConnectFieldTerm.class);
Root<QueryConnectFieldTerm> root = criteria.from(QueryConnectFieldTerm.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(QueryConnectFieldTerm_.field), field), criteriaBuilder.equal(root.get(QueryConnectFieldTerm_.name), name)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm in project muikku by otavanopisto.
the class WorkspaceConnectFieldIOHandler method retrieve.
@Override
public String retrieve(WorkspaceMaterialField field, WorkspaceMaterialReply reply) throws WorkspaceFieldIOException {
Map<String, String> answers = new HashMap<>();
QueryConnectField queryConnectField = (QueryConnectField) field.getQueryField();
List<QueryConnectFieldTerm> terms = queryConnectFieldController.listConnectFieldTermsByField(queryConnectField);
for (QueryConnectFieldTerm term : terms) {
WorkspaceMaterialConnectFieldAnswer connectFieldAnswer = workspaceMaterialFieldAnswerController.findWorkspaceMaterialConnectFieldAnswerByFieldAndReplyAndTerm(field, reply, term);
if ((connectFieldAnswer != null) && (connectFieldAnswer.getCounterpart() != null)) {
answers.put(term.getName(), connectFieldAnswer.getCounterpart().getName());
}
}
try {
return new ObjectMapper().writeValueAsString(answers);
} catch (IOException e) {
throw new WorkspaceFieldIOException("Could not marshal field response", e);
}
}
use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm 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()));
}
}
}
use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm in project muikku by otavanopisto.
the class QueryConnectFieldTermDAO method create.
public QueryConnectFieldTerm create(QueryConnectField field, String name, String text, QueryConnectFieldCounterpart counterpart) {
QueryConnectFieldTerm queryConnectFieldTerm = new QueryConnectFieldTerm();
queryConnectFieldTerm.setName(name);
queryConnectFieldTerm.setText(text);
queryConnectFieldTerm.setField(field);
queryConnectFieldTerm.setCounterpart(counterpart);
return persist(queryConnectFieldTerm);
}
use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm in project muikku by otavanopisto.
the class QueryConnectFieldTermDAO method listByField.
public List<QueryConnectFieldTerm> listByField(QueryConnectField field) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<QueryConnectFieldTerm> criteria = criteriaBuilder.createQuery(QueryConnectFieldTerm.class);
Root<QueryConnectFieldTerm> root = criteria.from(QueryConnectFieldTerm.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(QueryConnectFieldTerm_.field), field));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations