Skip to content

Commit

Permalink
[Fix partially kbss-cvut/fta-fmea-ui#428] Extend dao layer to support…
Browse files Browse the repository at this point in the history
… FaultTree status

- add FaultTreeDao.updateStatus
- add ManagedEntityDao.findSummary
  • Loading branch information
kostobog committed Jun 25, 2024
1 parent fd88818 commit 53e6d2e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
@Repository
public class FaultTreeDao extends ManagedEntityDao<FaultTree> {

public static final URI STATUS_PROP = URI.create(Vocabulary.s_p_status);

@Autowired
protected FaultTreeDao(EntityManager em, PersistenceConf config, IdentifierService identifierService, SecurityUtils securityUtils) {
super(FaultTree.class, em, config, identifierService, securityUtils);
Expand Down Expand Up @@ -168,4 +170,8 @@ public Query getSummariesQuery() {
.setParameter("pCreator", P_CREATOR)
.setParameter("pLastEditor", P_LAST_EDITOR);
}

public void updateStatus(URI faultTree, Status status){
super.addOrReplaceValue(faultTree, STATUS_PROP, status, faultTree);
}
}
47 changes: 31 additions & 16 deletions src/main/java/cz/cvut/kbss/analysis/dao/ManagedEntityDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
import cz.cvut.kbss.jopa.model.metamodel.Attribute;
import cz.cvut.kbss.jopa.model.metamodel.EntityType;
import cz.cvut.kbss.jopa.model.query.Query;
import cz.cvut.kbss.jopa.vocabulary.DC;

import java.net.URI;
Expand Down Expand Up @@ -75,8 +76,30 @@ public void setChangedByContext(URI context, Date date){

public List<T> findAllSummaries(){
try {
List<ManagedEntity> ret = em.createNativeQuery("""
List<ManagedEntity> ret = getSummariesQuery()
.getResultList();

return ret.stream().map(s -> s.asEntity(type)).toList();
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
}

public T findSummary(URI managedEntityUri){
try {
ManagedEntity ret = (ManagedEntity)getSummariesQuery()
.setParameter("_uri", managedEntityUri)
.getSingleResult();
return ret.asEntity(type);
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
}

public Query getSummariesQuery(){
return em.createNativeQuery("""
SELECT * WHERE {
BIND(?_uri as ?uri)
?uri a ?type.
?uri ?pName ?name.
OPTIONAL{?uri ?pDescription ?description.}
Expand All @@ -85,21 +108,13 @@ public List<T> findAllSummaries(){
OPTIONAL{?uri ?pCreator ?creator.}
OPTIONAL{?uri ?pLastEditor ?lastEditor.}
}""", "ManagedEntitySummary")
.setParameter("type", typeUri)
.setParameter("pName", P_HAS_NAME)
.setParameter("pDescription", P_HAS_DESCRIPTION)
.setParameter("pCreated", P_CREATED)
.setParameter("pModified", P_MODIFIED)
.setParameter("pCreator", P_CREATOR)
.setParameter("pLastEditor", P_LAST_EDITOR)
.getResultList();

return ret.stream().map(s -> s.asEntity(type)).toList();
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
.setParameter("type", typeUri)
.setParameter("pName", P_HAS_NAME)
.setParameter("pDescription", P_HAS_DESCRIPTION)
.setParameter("pCreated", P_CREATED)
.setParameter("pModified", P_MODIFIED)
.setParameter("pCreator", P_CREATOR)
.setParameter("pLastEditor", P_LAST_EDITOR);
}



}

0 comments on commit 53e6d2e

Please sign in to comment.