-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from gessi-chatbots/getAllFeaturesByMobileAppl…
…ication Get all features by mobile application
- Loading branch information
Showing
14 changed files
with
521 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/upc/edu/gessi/repo/repository/DocumentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package upc.edu.gessi.repo.repository; | ||
|
||
|
||
|
||
import upc.edu.gessi.repo.dto.DigitalDocumentDTO; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
public interface DocumentRepository extends RDFCRUDRepository<DigitalDocumentDTO> { | ||
Map<String, Integer> findAllDocumentTypeFeaturesWithOccurrences(String documentType); | ||
|
||
List<String> findAllDistinctDocumentTypeFeatures(String documentType); | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
src/main/java/upc/edu/gessi/repo/repository/FeatureRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package upc.edu.gessi.repo.repository; | ||
|
||
|
||
|
||
import upc.edu.gessi.repo.dto.Review.FeatureDTO; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
public interface FeatureRepository extends RDFCRUDRepository<FeatureDTO> { | ||
Map<String, Integer> findAllWithOccurrences(); | ||
|
||
List<String> findAllDistinct(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/upc/edu/gessi/repo/repository/impl/DocumentRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
package upc.edu.gessi.repo.repository.impl; | ||
|
||
import org.eclipse.rdf4j.model.IRI; | ||
import org.eclipse.rdf4j.repository.http.HTTPRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Repository; | ||
import upc.edu.gessi.repo.dto.DigitalDocumentDTO; | ||
import upc.edu.gessi.repo.dto.Review.FeatureDTO; | ||
import upc.edu.gessi.repo.exception.NoObjectFoundException; | ||
import upc.edu.gessi.repo.exception.ObjectNotFoundException; | ||
import upc.edu.gessi.repo.repository.DocumentRepository; | ||
import upc.edu.gessi.repo.repository.FeatureRepository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Repository | ||
public class DocumentRepositoryImpl implements DocumentRepository { | ||
|
||
private final HTTPRepository repository; | ||
|
||
|
||
@Autowired | ||
public DocumentRepositoryImpl(final @Value("${db.url}") String url, | ||
final @Value("${db.username}") String username, | ||
final @Value("${db.password}") String password) { | ||
repository = new HTTPRepository(url); | ||
repository.setUsernameAndPassword(username, password); | ||
|
||
|
||
} | ||
|
||
@Override | ||
public Map<String, Integer> findAllDocumentTypeFeaturesWithOccurrences(String documentType) { | ||
return new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public List<String> findAllDistinctDocumentTypeFeatures(String documentType) { | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public DigitalDocumentDTO findById(String id) throws ObjectNotFoundException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<DigitalDocumentDTO> findAll() throws NoObjectFoundException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<DigitalDocumentDTO> findAllPaginated(Integer page, Integer size) throws NoObjectFoundException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public IRI insert(DigitalDocumentDTO dto) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DigitalDocumentDTO update(DigitalDocumentDTO entity) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void delete(String id) { | ||
|
||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
src/main/java/upc/edu/gessi/repo/repository/impl/FeatureRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package upc.edu.gessi.repo.repository.impl; | ||
|
||
import org.apache.commons.text.WordUtils; | ||
import org.eclipse.rdf4j.model.IRI; | ||
import org.eclipse.rdf4j.model.Statement; | ||
import org.eclipse.rdf4j.model.ValueFactory; | ||
import org.eclipse.rdf4j.model.impl.SimpleValueFactory; | ||
import org.eclipse.rdf4j.query.BindingSet; | ||
import org.eclipse.rdf4j.query.TupleQuery; | ||
import org.eclipse.rdf4j.query.TupleQueryResult; | ||
import org.eclipse.rdf4j.repository.RepositoryConnection; | ||
import org.eclipse.rdf4j.repository.http.HTTPRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Repository; | ||
import upc.edu.gessi.repo.dto.DocumentType; | ||
import upc.edu.gessi.repo.dto.Feature; | ||
import upc.edu.gessi.repo.dto.MobileApplication.MobileApplicationBasicDataDTO; | ||
import upc.edu.gessi.repo.dto.MobileApplication.MobileApplicationFullDataDTO; | ||
import upc.edu.gessi.repo.dto.Review.FeatureDTO; | ||
import upc.edu.gessi.repo.dto.Review.ReviewDTO; | ||
import upc.edu.gessi.repo.dto.SimilarityApp; | ||
import upc.edu.gessi.repo.dto.graph.GraphApp; | ||
import upc.edu.gessi.repo.exception.MobileApplications.MobileApplicationNotFoundException; | ||
import upc.edu.gessi.repo.exception.MobileApplications.NoMobileApplicationsFoundException; | ||
import upc.edu.gessi.repo.exception.NoObjectFoundException; | ||
import upc.edu.gessi.repo.exception.ObjectNotFoundException; | ||
import upc.edu.gessi.repo.repository.FeatureRepository; | ||
import upc.edu.gessi.repo.repository.MobileApplicationRepository; | ||
import upc.edu.gessi.repo.repository.ReviewRepository; | ||
import upc.edu.gessi.repo.util.*; | ||
|
||
import java.sql.Date; | ||
import java.util.*; | ||
|
||
@Repository | ||
public class FeatureRepositoryImpl implements FeatureRepository { | ||
|
||
private final HTTPRepository repository; | ||
|
||
private final FeatureQueryBuilder featureQueryBuilder; | ||
|
||
|
||
@Autowired | ||
public FeatureRepositoryImpl(final @Value("${db.url}") String url, | ||
final @Value("${db.username}") String username, | ||
final @Value("${db.password}") String password, | ||
final FeatureQueryBuilder featureQueryBuild) { | ||
repository = new HTTPRepository(url); | ||
repository.setUsernameAndPassword(username, password); | ||
featureQueryBuilder = featureQueryBuild; | ||
|
||
|
||
} | ||
|
||
|
||
@Override | ||
public FeatureDTO findById(String id) throws ObjectNotFoundException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<FeatureDTO> findAll() throws NoObjectFoundException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<FeatureDTO> findAllPaginated(Integer page, Integer size) throws NoObjectFoundException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public IRI insert(FeatureDTO dto) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public FeatureDTO update(FeatureDTO entity) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void delete(String id) { | ||
|
||
} | ||
|
||
private TupleQueryResult runSparqlQuery(final String query) { | ||
RepositoryConnection repoConnection = repository.getConnection(); | ||
TupleQuery tupleQuery = repoConnection.prepareTupleQuery(query); | ||
return tupleQuery.evaluate(); | ||
} | ||
|
||
@Override | ||
public Map<String, Integer> findAllWithOccurrences() { | ||
TupleQueryResult result = runSparqlQuery(featureQueryBuilder.findAllFeaturesWithOccurrencesQuery()); | ||
Map<String, Integer> featureOcurrencesDict = new HashMap<>(); | ||
while (result.hasNext()) { | ||
BindingSet bindings = result.next(); | ||
if(bindings.getBinding("feature") != null | ||
&& bindings.getBinding("feature").getValue() != null | ||
&& bindings.getBinding("count") != null | ||
&& bindings.getBinding("count").getValue() != null) { | ||
featureOcurrencesDict.put( | ||
bindings.getBinding("feature").getValue().stringValue(), | ||
Integer.valueOf(bindings.getBinding("count").getValue().stringValue()) | ||
); | ||
} | ||
} | ||
return featureOcurrencesDict; | ||
} | ||
|
||
@Override | ||
public List<String> findAllDistinct() { | ||
TupleQueryResult result = runSparqlQuery(featureQueryBuilder.findAllDistinctFeaturesQuery()); | ||
List<String> featuresList = new ArrayList<>(); | ||
while (result.hasNext()) { | ||
BindingSet bindings = result.next(); | ||
if(bindings.getBinding("feature") != null | ||
&& bindings.getBinding("feature").getValue() != null) { | ||
featuresList.add( | ||
bindings.getBinding("feature").getValue().stringValue()); | ||
} | ||
} | ||
return featuresList; | ||
} | ||
} |
Oops, something went wrong.