Mongo Aggregation to replace Java 8 Streaming - mongodb

I am new to "Mongodb". I have the following java code where I find an list of permission and from each permission I trying to get the list of actions that contains this uuid. How can I write the equivalent in JPA for Mongodb aggregation. The problem with the current code is that I get out of memory errors because if the document Permission table is big my java code will get out of memory issue.
Any help or hint would be greatly appreciated it!!
`
List<PermissionEntity> permissionEntities = permissionRepository.findAll();
if (!ObjectUtils.isEmpty(permissionEntities)) {
Optional<PermissionEntity> permission = permissionEntities.stream().filter(permissionEntity ->
permissionEntity.getActions()!= null && permissionEntity.getActions().contains(uuid)
).findAny();
if (!ObjectUtils.isEmpty(permission)) {
throw new ResponseStatusException( HttpStatus.CONFLICT, "EndPoint in use");
}
actionRepository.deleteByUuid(uuid);
}
`
I wrote it in Java and I trying to write it in JPA.

Related

Can I use flutter to create an index on firestore?

I'm using the following flutter code to query firestore which orders the data using the field timestamp.
var results = Firestore.instance.collection('post').orderBy('timestamp').getDocuments().then((value) {
var list = value.documents;
return list.map((doc) {
return doc.documentID;
}).toList();
});
When I run this code, it throws the below exception saying an index is required:
W/Firestore(31110): (21.3.0) [Firestore]: Listen for Query(app/jQH7Fp9xCZWYiqZRe7lE/post where readAccess array_contains_any [WzKImODx6WYVqdSW3D9Az3xrUnM2, PUBLIC] order by -timestamp, -name) failed: Status{code=FAILED_PRECONDITION, description=The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/....
The exception even comes with a nice link. When opening that link, a nice UI pops up giving me the ability to create the index, with just a simple click:
Question: simple as the above may seem, I'm not very happy with this. I prefer to be able to create the index from fluttercode. In code I'm looking for something like the below:
Firestore.instance.collection('post').API-TO-CREATE-INDEX('timestamp');
Does it exist? Please advise. Many thanks.
It's not possible to create an index from client apps. You have three main choices:
Clicking the link you already saw.
Using the Firebase CLI to deploy the index from the command line.
Using the gcloud CLI to also deploy from the command line
See also the documentation on managing indexes.

Cast Exception When Using Foreach on Microsoft.SharePoint.Client.ListCollection

I have exhausted my resources on this issue. I'm hoping you all can assist me.
I have an agent polling Microsoft O365 for list collections in order to walk through all the lists in a given site. Here is the code:
Microsoft.SharePoint.Client = CSOM
ListCollection lists = CSOM.web.Lists;
clientContext.Load(lists);
clientContext.ExecuteQuery();
try
{
foreach(CSOM.List list in lists
{
do.stuff()
}
}
catch(Excetion ex)
{
// I get this excetpion in my log at CSOM.List after 'in lists' is read.
/*System.InvalidCastException: Unable to cast object of type
'System.Collections.Generic.Dictionary`2[System.String,System.Object]'
to type 'Microsoft.SharePoint.Client.List'.*/
}
When in debug and tracing through the code ex appears 'null', but I still get the excetion in my debug logs when I write ex.ToString() to a log file.
I am using .Net 4.6. This code has worked before, during dev tests, but wont work running in a service. I can't find any Namespace issues. The O365 account I amusing has 2FA disabled and has admin rights. Any thoughts would be very helpful. Thank you.

error.CannotStartupOSGIPlatform issue when running birt

I'm in the midst of implementing Birt 4.6.0 into my gwt application. Unfortunately whenever I run a specific section of the program, I get the following error:
org.eclipse.birt.core.exception.BirtException:
error.CannotStartupOSGIPlatform at
org.eclipse.birt.core.framework.Platform.startup(Platform.java:81)
I've done some searching and one thread mentioned a permissions error but I am not sure what that entails. What does this mean?
EDIT Just read another article that suggests that it may be an issue with my classpath but I already added all the jar files from ReportEngine/lib to my buildpath. Anyone know what jar files I am supposed to include?
the offending code:
public static synchronized IReportEngine getBirtEngine(ServletContext sc) {
if (birtEngine == null) {
EngineConfig config = new EngineConfig();
java.util.HashMap map = config.getAppContext();;
map.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, SegnalazioniDbManager.class.getClassLoader());
config.setAppContext(map);
IPlatformContext context = new PlatformServletContext(sc);
config.setPlatformContext(context);
try {
Platform.startup(config); //problem begins here
.....
}
[1]: http://developer.actuate.com/community/forum/index.php?/topic/20933-errorcannotstartuposgiplatform/
Yes it is indeed a permission error.
The relevant file is:
WEB-INF/platform/configuration/org.eclipse.osgi/.manager/.fileTableLock
You need to give access to the Birt user.

MongoDb toArray

I am using mongodb and in the following code I am using mongodb find().toArray(), but it is giving me the error "Cannot read property 'toArray' of undefined"
req.activedb.collection('items').find().toArray(function (err, data) {
//...some code
})
whereas when I am using findOne(), then it is working properly.
req.activedb.collection('items').findOne(function (err, records) {
console.log(err, records); //Getting a single record here
})
req.activedb is my current db instance
Can you please tell me, what is missing here ?
I have resolved this issue.
Actually I was using mongoose to connect with my db, so it does not support find(). So now I am connecting to the db using new Db() method and it is working properly.
I have run belows command its work for me.
posts is nothing but collection.
db.posts.find().toArray();
You might be, you are making mistake in syntax .

Displaying data from mongoskin through HTML

I am using mongodb to store data and i wrote a simple js script using mongoskin to query and retrieve data from a collection and it works fine...
var db = require('mongoskin').db('winter.ceit.uq.edu.au/openbeacon');
var time = 0;
var tagid = 1101;
db.collection('set1').find({tag : {'$elemMatch': {id: tagid,name :"reader07"}}},function(err, result) {
if (err) throw err;
result.each(function(err, band) {
console.log(band.tag);
time += band.time;
});
});
However i need a way to integrate this functionality into a webpage...so say i press a button on the page, the js script runs and the queried data is displayed on the webpage. When i try using this javascript in a HTML file, it erros saying "module not found" since im referencing the index.js for mongoskin and mongodb as the source in my html file.....
Please lemme know what are the ways (preferably the simplest ways) to do this.
thank you.
Try looking for example applications
here is one
https://github.com/christkv/tic-tac-toe-steps