How do I use the messages file to create my own messagesApi - playframework-2.6

In my play-framework application, there is a messages file which I can use to define my own messages. Eg
##############Application Error messages
error.incorrectBodyType=Incorrect body type. Body type must be JSON
error.incorrectBodyContentInLoginRequest=No Login info found in the request. Check format
error.incorrectUsernameOrPassword = Incorrect username or password
error.unregisteredUser = registration not complete
error.ghostUsername = No record found for the username
error.unauthenticated = You must first sign in
error.unauthorized = You are not permitted
####### Application Success Messages
success.signoutSuccessful = Signout Successful
The play frameworks makes these messages available to my Controller and I can use them like the messagesApi("error.unauthenticated")(langs.availables(0)).
I am unable to figure out how I can use the messages file in my unit tests. I am using compile time injection and am creating my own instances of the required classes. To create MessagesApi, there is a DefaultMessagesApi method but it take a map, not a File.
I am able to create the messages in my unit tests as follows but I have to duplicate the effort of copying messages from messages file to this map
val messagesApi = new DefaultMessagesApi( //takes map of maps. the first is the language file, the 2nd is the map between message title and description
Map("en" -> //the language file
Map("error.incorrectBodyType" -> "Incorrect body type. Body type must be JSON",
"error.incorrectUsernameOrPassword"->"Incorrect username or password",
"error.incorrectBodyContentInLoginRequest"->"No Login info found in the request. Check format", //map between message title and description
"error.unregisteredUser" -> "registration not complete",
"error.ghostUsername" -> "No record found for the username",
"success.signoutSuccessful" -> "Signout Successful",
"error.unauthenticated" -> "You must first sign in",
"error.unauthorized" -> "You are not permitted")
)
)
Is there a way I can read the messages file and use it in my test case?

My test case already extended OneAppPerSuiteWithComponents. I used components.messagesApi of OneAppPerSuiteWithComponents which was already available and reads from the messages file

Related

Power Automate error when trying to add an attachment array from plumsail

I have a Plumsail form where a user can attach several pdf or word documents. In power automate I create an array of these documents and then attach the array to the "Start and wait for approval" action. When I run it, I get the error below:
The request failed. Error code: 'InvalidRequestContent'. Error
Message: 'The request content was invalid and could not be
deserialized: 'Could not find member 'ContentBytes' on object of type
'ApprovalsConnectorAttachment'.
I'm assuming you followed the How to send an email from Plumsail form with Power Automate Plumsail guide as it tells you to assign the HTTP GET file response to a property named ContentBytes.
While this will work with the Send an Email (V2) action (from the guide) the Start and wait for an approval action expects a property named content content.
To fix the problem append the following object to the array (note the contentproperty):
{
"name": #{items('Apply_to_each_2')?['file']},
"content": #{body('HTTP')}
}
or as an image:

PowerApps Custom Connector: How to POST binary data in request body?

Using Postman to test an API, I'm able to select Body/binary then choose an image file stored locally. Postman inserts binary data somehow into the request and I get a favorable response:
When trying to build this as a Custom Connector in PowerApps, I can't find any info on what the schema for the Body of the request should be.
When I try to add a generic {"body": ""} body to the connector with a string type of binary, I receive this error:
Specified swagger has the following errors: 'Definition is not valid. Error: 'Error : paths/~1prebuilt~1analyze/post/parameters/2/schema/properties/body : A schema with type/format 'string/binary' can only be at the top level of a body or formData parameter. '
I was running into the same problem.
Body:
""
When you have clicked Import, go to the request -> body -> body and click the three dots -> Edit.
Under Body, it will say "key-body-output". Click the three dots and click Edit.
Change Type to String (if not already) and change Format to Binary. Change Is required to Yes.
Update the connector and you can now use the custom connector with PowerApps by using ImageX.Image for the body property for example.

Serverless - Change the content before deploy

I'm using Serverless for working with our aws lambda / appsync.
For Error Handling, we are keep erro code with message in a json file. The Codes will be unique. Something like this:
//error-code.json
{
"1"": { code: 1, message: "Invalid User Input"},
"2"": { code: 2, message: "Invalid Input"},
//... so on
}
This wil lbe deploy as layer and all the lambda will use it. Issue is we cannot use it in the resolve template. There are some of the resolver will be only template file. These template files cannot access the json file nor can access the layer. How can I use the error-code.json here?
Solution 1:
Manually write the error code in templates and make sure there are alway unique. Something like this:
#set(#errorInfo = {
"erroCode": "1",
"errorMessage": "Invalid Input"
})
$util.error("Invalid Input", "errorType", $ctx.arguments,#errorInfo)
Rejected: Becasue we have to manually check everytime for the unique of error code. In case of lot of template file, we cannot rely on it.
Solution 2:
Create a table with error code (unique) and error message. Use this table to send error from template.
Rejected: Because we use multiple app sync instance and they all connect to dirferent database. So we have to make this table in all database, and thus unique across the app-sync is not maintained.
Solution 3:
Write the placeholder in vtl where we want to send the error. Before Deploy, replace the placeholder with the actual code using pre-hook script, but not in the actual vtl file but in the generated package that serverless deploy. Does Serverless even such thing?
if your errors are all static, there is one more option for consideration.
You create one more file that holds all errors defined in Velocity.
$util.qr( $ctx.stash.put("errors", {}) ) $util.qr(
$util.qr( $ctx.stash.errors.put("ONE", { "code": 1, "message": "Invalid User
Input"} )
...
$util.qr( $ctx.stash.errors.put("TWENTY", { "code": 20, "message": "20th error description"} )
For every velocity resolver that throws errors, you inject pre-defined errors at the beginning of its request mapping's file. Whenever you want to throw an error, it's done by retrieving a pre-defined error from $ctx.stash
$util.error ( $ctx.stash.errors.ONE.message, $ctx.stash.errors.ONE.code )
The error file is generated from error-code.json, or manually typed again for simplicity. $ctx.stash is used because stash is accessible from everywhere in a resolver, including pipeline ones.

Is there a way to preserve a signature in RDOMail.Reply like MailItem.Reply does?

I tried obtaining the reply to the mail by using RDOMail.Reply method.
However, after inspecting the returned object, I've noticed that the signature is not part of the HTMLBody property, as it is when using method MailItem.Reply (which I'm not using because it throws 0x80004004 (E_ABORT) exception). Also, attachments that would be needed for the signature if it contains images are not preserved as they are with MailItem.Reply.
I've tried applying the signature separately, using Signature object. This adds signature to the HTMLBody, but doesn't use the _MailAutoSig attribute to mark the signature part therefore if I select "Change signature" from Outlook Ribbon, signature doesn't get replaced because Outlook has no way of knowing it is a signature.
Is there a way to obtain reply from RDOMail that would contain signature Outlook knows how to replace?
var rdoMail = session.GetMessageFromID(entryid);
var reply = rdoMail.Reply();
reply.HTMLBody = "";
var Account = session.Accounts.GetOrder(rdoAccountCategory.acMail).Item(1);
var signature = Account.ReplySignature;
signature.ApplyTo(reply, false);
reply.Save();
This is a known issue/case when dealing with Extended MAPI code and it is not related to Redemption only. See Messages that are created outside Outlook do not include the default Outlook email signature for more information.
Your choices are:
Mimic the Outlook behavior by adding all the necessary parts like _MailAutoSig attribute to the message body.
Use the Outlook object model with the Reply method and then getting the Redemption equivalent by using the GetRDOObjectFromOutlookObject method. But as far as I can tell, looking at the exception you get, it is not possible because the code is used from a secondary thread, right?
You can use its RDOAccount object (accessible in any language, including VBA). New message signature name is stored in the 0x0016001F property, reply signature is in 0x0017001F.
You can also use the RDOAccount.ReplySignature and NewSignature properties.
Redemption also exposes RDOSignature.ApplyTo method that takes a pointer to the RDOMail object and inserts the signature at the specified location correctly merging the images and the styles:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Drafts = Session.GetDefaultFolder(olFolderDrafts)
set Msg = Drafts.Items.Add
Msg.To = "user#domain.demo"
Msg.Subject = "testing signatures"
Msg.HTMLBody = "<html><body>some <b>bold</b> message text</body></html>"
set Account = Session.Accounts.GetOrder(2).Item(1) 'first mail account
if Not (Account Is Nothing) Then
set Signature = Account.NewMessageSignature
if Not (Signature Is Nothing) Then
Signature.ApplyTo Msg, false 'apply at the bottom
End If
End If
Msg.Send

How a code can be assigned to an Application custom error messages

How a code can be given to an Application custom error messages in Ruby on Rails. when a user sees an error, he should be able to know both its error code and message.
For example, I want to achieve the following result, in case of respective error.
CODE Message
4081 You are not allowed to view the private document
5082 Company with this name already present
5034 Page removed
This is a multilingual application. Translations for error messages are present in /config/locales/en.yml. I'm using i18n gem for translation. This is how translation for error messages are present without code.
errors:
messages:
private_document: "You are not allowed to view the private document"
company_name: "Company with this name already present"
page_remove: "Page removed"
Something like this are you looking for?....
errors:
messages:
4081 "You are not allowed to view the private document"
5082 "Company with this name already present"
5034 "Bidding end date should be greater than current date and time"
Use code instead of name.

Resources