Discord JDA check OnlineStatus of a Bot - java

I'm trying to create a Status Command which, among other things, queries whether a particular Discord bot is online. However, I get a null pointer exception when I execute the command.
Member jutils_bot = Objects.requireNonNull(event.getGuild()).getMemberById("937273424852705342");
assert jutils_bot != null;
embed.setDescription("Auth System\n" + (code == 200 ? ":white_check_mark:" : ":x:")
+ "\nWebsite\n" + websiteFile
+ "\nJUtils Bot\n" + (jutils_bot.getOnlineStatus() == OnlineStatus.ONLINE ? ":white_check_mark:" : ":x:"));
I have already checked my intents, however they are enabled.

Related

problem of associating a data source associated with Word mail merge from a java application (OLE communication)

I'm working on a java application that interacts with Word through an OLE library (org.eclipse.swt.ole.win32) to merge documents (mail merge).
the java method which makes it possible to merge has been working for several years without any particular problem.
but recently the data source can no longer be associated with the merge document.
This problem is random (on some workstations it works and on others it doesn't, yet same system configuration)
I have no explicit error reported on the java side
Here is the method that communicates with Word:
public void mergeDocument(File model, File source) throws Exception {
OleAutomation autoMailMerge = null;
LOGGER.log(new Status(IStatus.INFO, pluginID, "Merge d un document"));
LOGGER.log(new Status(IStatus.INFO, pluginID, "fichier modele: " + model.getCanonicalPath()));
LOGGER.log(new Status(IStatus.INFO, pluginID, "fichier source: " + source.getPath()));
openDocumentReadOnly(model);
autoMailMerge = OLEHelper.getAutomationProperty(autoDocument, "MailMerge");
if ((source != null) && (source.exists()) && (!source.isDirectory())) {
OLEHelper.invoke(autoMailMerge, "OpenDataSource", source.getPath());
} else {
throw new MSWordOleInterfaceException(MSWordOleInterfaceCst.MSG_ERROR_EMPTY_SOURCE_PATH
+ ((source == null) ? "null" : source.getPath()));
}
OLEHelper.invoke(autoMailMerge, "Execute");
OleAutomation autoDocumentMerged = getActiveDocument();
closeDocument(autoDocument);
activateDocument(autoDocumentMerged);
autoDocument = autoDocumentMerged;
autoMailMerge.dispose();
}
Merging by hand from Word (associating the data source and merging) works on workstations where the java application does not work.
thanks to the OLE command I validated that it is the data source which is not passed (on a workstation which works I have a return with the name of the source, on one or it does not work the return is empty)
LOGGER.log(new Status(IStatus.INFO, pluginID, "data source name: "
+ OLEHelper.getVariantProperty(autoDataSource, "Name").getString()));
-a temporary solution has been found, by deleting the registry key related to office:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Word\DocumentTemplateCache
but this is only a temporary solution, the problem comes back.

500 Internal Server Error instead of 404 in Spring Boot

When I try to find out the value that is not there in the database I get 500 Internal Server Error. I have already provided logic to throw ResourceNotFoundException error, but, it's not working for some reason. What do I need to do to get 404 ResourceNotFoundException instead of 500 Internal Server Error.
Here's my code:
#PostMapping("/start/{id}")
public ResponseEntity<String> startEvent(#PathVariable() Long id) {
Event event = this.eventRepository.findById(id).get();
if (event == null) {
throw new ResourceNotFoundException("Event with id " + id + " not found.");
}
event.setStarted(true);
this.eventRepository.save(event);
return ResponseEntity.ok("Event " + event.getName() + " has started");
}
I guess eventRepository.findById(id) //id = 200 returns 500 response as record with id 200 does not exist in the database. What should I do to get ResourceNotFoundException?
eventRepository.findById returns Optional (in Spring Data JPA 2.0.6, see https://docs.spring.io/spring-data/jpa/docs/2.0.6.RELEASE/reference/html/#repositories.core-concepts)
Optional.get on empty optional causes NoSuchElementException (https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#get--). Your if (event == null) comes too late.
Checking stactrace, you should see that exception comes from line with this.eventRepository.findById and actual exception is NoSuchElementException
To fix that you should change your code to
Optional<Event> optionalEvent= this.eventRepository.findById(id);
if (!optionalEvent.isPresent()) {
throw new ResourceNotFoundException("Event with id " + id + " not found.");
}
Event event=optionalEvent.get();
//the rest of your logic
You may also write your code in more functional way
Event event = this.eventRepository
.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Event with id " + id + " not found."))
Summary
Do not call get() on Optional without checking if it is present (using isPresent() method)
eventRepository.findById() return an Optional
Therefore you have to test for existence before get()
Optional<Event> optEvent = eventRepository.findById();
if (!optEvent.isPresent()) {
//throw exception here
}

Facing "system#unknownerror" when trying to get the ASSET details in maximo from java code

Here I am trying to get ASSET details in simple java
Here is the code
MXSession session = MXSession.getSession();
session.setHost("localhost:13400/MXServer");
session.setUserName(user);
session.setPassword(pwd);
session.connect();
The connection was successful.
Then I tried to get the asset details with the code
MboSetRemote assetMboSet = session.getMboSet("ASSET");
assetMboSet.setOrderBy("ASSETNUM");
MboRemote assetMbo;
for(int j=0; ((assetMbo = assetMboSet.getMbo(j)) != null); j++)
{
String assetNum = assetMbo.getString("ASSETNUM");
String location = assetMbo.getString("LOCATION");
String desc = assetMbo.getString("DESCRIPTION");
System.out.println(assetNum + " - " + location + " - " + desc);
}
it is giving me the error and could not proceed further in the line
MboSetRemote assetMboSet = session.getMboSet("ASSET");
saying
Exception in thread "main" psdi.util.MXSystemException: system#unknownerror
at psdi.util.RMISession.getMboSet(RMISession.java:330)
Please suggest me how to proceed
My friend I just tried your code scripth and it works fine, here is a snapshot of my environment which shows your work.
This problem may occur, If the admin mode is on OR you need to change take a look at sessions, to do that.
you can go to the users application.
Select action > manage sessions.
You can view users who are currently logged into the system.
You can log out a user from the system or log out and block a user from the system.
You can see the login history of users.

How to send content of a file in a tSendMail

i try since some days to send one mail with different informations from child job and father job.
see my jobs below:
and my tRunJob_3
at the end of this job, i can put informations from tAggregateRow in the email, but it send several email (one mail by condition "if" approved DeinitJob --- if --- tRunJob_3)
my file generated by tFileOutputDelimited_1 in the father job contains all the information i need to put in the final mail.
1: how to display these informations in one email (no attachement) ?
2: i have this error in my console:
For input string: "7.91'7.91"
multiple points
what it means ?
EDIT:
with the modification below, it send me 1 email with the informations collected
in my tjavaflex:
code initial
// start part of your Java code
boolean loop ;
System.out.println("## START\n#");
code principal
// here is the main part of the component,
// a piece of code executed in the row
// loop
// code sample:
System.out.println("## LOAD...\n#");
if ((String)globalMap.get("message") != null) {
globalMap.put("message", (String)globalMap.get("message") + row5.mag + " qt: " + row5.qt + " p1: " + row5.p1 + "\n" ) ;
}
code final:
// end of the component, outside/closing the loop
loop = true ;
System.out.println("## END\n#");
with a if loop between tjava and tsendmail
but still have my error:
For input string: "7.91'7.91"
multiple points

How can I get the name associated with an extension/peer without having an opened channel with the Asterisk's Java API?

I’m using FreePBX with Asterisk’s Java API.
For the moment, I’m able to display all my SIP peers with their respective states:
public void onManagerEvent(ManagerEvent event)
{
// Look if the event is a IP phone (Peer entry)
if(event instanceof PeerEntryEvent)
{
PeerEntryEvent ev = (PeerEntryEvent)event;
// Get the user extension
peer = ev.getObjectName();
// Add to the array
peersName.add(peer);
}
}
I’m able to display the phone number and name of both callers when a channel is open:
private String GetExtensionPeer(String extension)
{
for (AsteriskChannel e : channels)
if (e.number.equals(extension) && e.bridge != null )
for (AsteriskChannel channel : channels)
if (z.channel.equals(e.bridge))
return " with " + channel.number + " - " + channel.name;
return "";
}
But now, I would like to display the name of my extensions without a channel connection.
In FreePBX's panel, it's look like :
In freepbx you can get list of extensions from asterisk db. To see info, do
asterisk -rx "database show"
To get info use manager action "command" with DBGET.
Other option - got that info from freepbx's mysql db.

Categories