use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart in project muikku by otavanopisto.
the class QueryConnectFieldCounterpartDAO method findByFieldAndName.
public QueryConnectFieldCounterpart findByFieldAndName(QueryConnectField field, String name) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<QueryConnectFieldCounterpart> criteria = criteriaBuilder.createQuery(QueryConnectFieldCounterpart.class);
Root<QueryConnectFieldCounterpart> root = criteria.from(QueryConnectFieldCounterpart.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(QueryConnectFieldCounterpart_.field), field), criteriaBuilder.equal(root.get(QueryConnectFieldCounterpart_.name), name)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart 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.QueryConnectFieldCounterpart in project muikku by otavanopisto.
the class QueryConnectFieldCounterpartDAO method listByField.
public List<QueryConnectFieldCounterpart> listByField(QueryConnectField field) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<QueryConnectFieldCounterpart> criteria = criteriaBuilder.createQuery(QueryConnectFieldCounterpart.class);
Root<QueryConnectFieldCounterpart> root = criteria.from(QueryConnectFieldCounterpart.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(QueryConnectFieldCounterpart_.field), field));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart in project muikku by otavanopisto.
the class QueryConnectFieldCounterpartDAO method create.
public QueryConnectFieldCounterpart create(QueryConnectField field, String name, String text) {
QueryConnectFieldCounterpart queryConnectFieldCounterpart = new QueryConnectFieldCounterpart();
queryConnectFieldCounterpart.setName(name);
queryConnectFieldCounterpart.setText(text);
queryConnectFieldCounterpart.setField(field);
return persist(queryConnectFieldCounterpart);
}
use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart in project muikku by otavanopisto.
the class QueryConnectFieldController method deleteQueryConnectField.
public void deleteQueryConnectField(QueryConnectField queryField, boolean removeAnswers) {
queryFieldDeleteEvent.fire(new QueryFieldDeleteEvent(queryField, removeAnswers));
for (QueryConnectFieldTerm term : listConnectFieldTermsByField(queryField)) {
queryConnectFieldTermDAO.delete(term);
}
for (QueryConnectFieldCounterpart counterpart : listQueryConnectFieldCounterpartByField(queryField)) {
queryConnectFieldCounterpartDAO.delete(counterpart);
}
queryConnectFieldDAO.delete(queryField);
}
Aggregations