With following code, serviceIdSegment is null while serviceId is not null.
class MySubResource {
#GET
#Path("{serviceId: .+}")
public Response readById(#PathParam String serviceId) {
// serviceId is not null
// why serviceIdSegment is null?
}
#PathParam("serviceId");
private PathSegment serviceIdSegment;
}
Can anybody please tell me why?
I noticed, when I tried to answer, that this question is mine.
The readById method is lazily evaluated after the root resource class is matched.
Related
I was searching for answears but I couldn't find it. It might be a beginner question, anyhow I am stuck.
What I am trying to write is a test in Apex. Basically the Apex code gets field names from one specific object. Each fieldname will be shown in a picklist, one after the other (that part is a LWC JS and HTML file).
So, only want to test the Apex for the moment.
I don't know how to check that a list contains 2 parameters, and those parameters are object and field. Then the values are correctly returned, and I don't know how to continue.
Here's the Apex class with the method, which I want to test.
public without sharing class LeadController {
public static List <String> getMultiPicklistValues(String objectType, String selectedField) {
List<String> plValues = new List<String>();
Schema.SObjectType convertToObj = Schema.getGlobalDescribe().get(objectType);
Schema.DescribeSObjectResult objDescribe = convertToObj.getDescribe();
Schema.DescribeFieldResult objFieldInfo = objDescribe.fields.getMap().get(selectedField).getDescribe();
List<Schema.PicklistEntry> picklistvalues = objFieldInfo.getPicklistValues();
for(Schema.PicklistEntry plv: picklistvalues) {
plValues.add(plv.getValue());
}
plValues.sort();
return plValues;
}
}
I welcome any answers.
Thank you!
This might be a decent start, just change the class name back to yours.
#isTest
public class Stack73155432Test {
#isTest
public static void testHappyFlow(){
List<String> picklistValues = Stack73155432.getMultiPicklistValues('Lead', 'LeadSource');
// these are just examples
System.assert(!picklistValues.isEmpty(), 'Should return something');
System.assert(picklistValues.size() > 5, 'At least 5 values? I dunno, whatever is right for your org');
System.assert(picklistValues[0] < picklistValues[1], 'Should be sorted alphabetically');
System.assert(picklistValues.contains('Web'), 'Or whatever values you have in the org');
}
#isTest
public static void testErrorFlow(){
// this is actually not too useful. You might want to catch this in your main code and throw AuraHandledExceptions?
try{
Stack73155432.getMultiPicklistValues('Account', 'AsdfNoSuchField');
System.assert(false, 'This should have thrown');
} catch(NullPointerException npe){
System.assert(npe.getMessage().startsWith('Attempt to de-reference a null object'), npe.getMessage());
}
}
}
Android Studio 3.0
I am have java code that I am converting to Kotlin for my project.
public String getAuthUserEmail() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String email = null;
if (user != null) {
email = user.getEmail();
}
return email;
}
I have converted it to koklin like this:
fun getAuthUserEmail(): String? {
val user: FirebaseUser? = FirebaseAuth.getInstance().currentUser
return user?.email
}
I am just wondering in my kotlin version if the user happens to be null. Should I need to have an if condition to check if the user is null?
I could have the function as a one line
fun getAuthUserEmail(): String? {
return FirebaseAuth.getInstance().currentUser.email?
}
And would the calling function need to handle a null string that could be return from the function?
Many thanks for any suggestions
Should I need to have an if condition to check if the user is null?
According to Firebase's doc:
Returns the currently signed-in FirebaseUser or null if there is none.
Use getCurrentUser() != null to check if a user is signed in.
So, it depends on how you want to handle when there is no signed-in user.
If you want the function to be one-lined, you can chain it like this:
fun getAuthUserEmail(): String? {
return FirebaseAuth.getInstance().currentUser?.email
}
It will return null if currentUser is null or currentUser?.email is null.
Edit: If you simply want to return email if it exists. It's ok to write it in one line, since safe calls can be chained.
Small advice. If you are sure object shouldn't be null, but is nullable, use !! to mark object as one that shouldn't be null. If app crashes it is okay as it shows you that u did somewhere bad implementation. Look at the structure of your implementation to know wheter object should be null or not, a lot of devs overuse objet?.let without looking if this object should be null or not
I am just wondering in my kotlin version if the user happens to be
null. Should I need to have an if condition to check if the user is
null?
Depend on the case how you are going to handle scenario but you can form
your data in Elvis Operator way as below:
fun getAuthUserEmail(): String? {
return FirebaseAuth.getInstance().currentUser?.email ? "No data"
}
I have the following problem: When I use a Model/Repository with a different mapping, I don't get any property and values.
I've mapped the Repository to fetch the data from table sys_files.
I do get the UID, I also do get the PID. Unfortunately, I do not get any other property or the value.
My Repository is a simple Repository mapped to sys_files.
Unfortunately, I do not get any orther property.
Thanks a lot.
Greetz
Have you defined the mapping in the ext_typoscript_setup.txt?
config.tx_extbase {
persistence {
classes {
Vendor\Package\Domain\Model\MyModel {
mapping {
tableName = sys_file
}
}
}
}
}
You also need to assign the needed fields in your domain model.
namespace Vendor\Package\Domain\Model;
class MyModel
{
/**
* #var string
*/
protected $identifier;
public function getIdentifier()
{
return $this->identifier;
}
public function setIdentifier($identifier)
{
$this->identifier = $identifier;
}
}
There is a checklist when you mapping a model to a table:
1. Create the ext_typoscript_setup.txt file in the extension root path.
There you have to write the following code:
config.tx_extbase{
persistence {
classes {
YourModel.mapping{
table = table_you_want_to_map
}
}
}
}
Avoid to add backslash before model namespace
3. Clear cache from install tool. If nothing happens, then, try to delete the typo3temp/autoload folder.
4. The fields from the model should be camelCase.
Example of field: field_name in your model will be fieldName
5. Check the getters in your model.
Okay, problem solved - almost.
I can't get hash values. I don't know why but it is how it is.
I get the values of each column except "identifier_hash", "folder_hash". These attributes are always NULL.
Now I only have to make a new file_reference record in my db when I add a new relation.
I am trying to expand child entity in entity but getting following error : 400 Bad Request
Query option 'Expand' is not allowed. To allow it, set the 'AllowedQueryOptions' property on QueryableAttribute or QueryValidationSettings.
I set [EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]this property but no luck, then also fire same error.
Here is my URI :
localhost/OData/Ticket?$expand=Location
I also trying for get count of record but count also not working for me.Here is my URI for count.
localhost/OData/Ticket?$count=true
But here also I getting 400 Bad request error with following message :
The query parameter '$count' is not supported.
I did lot of google and found some related issues but that not work for me. Here is my Code:
Controller :
public class ODataTicketController : ODataController
{
[ODataRoute]
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
public IQueryable<Ticket> Get()
{
return db.Tickets;
}
}
Please help to resolve this.
Thank you.
Finally working all odata query on my controller. Just need IQueryable to IHttpActionResult. Now its working fine. Here is updated controller.
public class ODataTicketController : ODataController
{
[EnableQuery]
public IHttpActionResult<Ticket> Get()
{
var result = db.Tickets;
return Ok(result);
}
}
Hope it will help someone.
Thank you.
I've had a MVC 4 / Entity web project dropped into my lap, and I've never used either before. I'm getting through it but the simple things are really tripping me up - Like hiding or displaying a link in my layout based on a parameter in the database.
I created a function in my HomeController that simply sets 2 bools in the ViewBag for whether or not a person is a manager or superuser. I call that function using
#Html.Action("SetupViewBag", "Home")
which sits right after the <body> tag in my layout. Here is the code for SetupViewBag:
public void SetupViewBag()
{
ViewBag.IsManager = ADAccess.IsManager(SessionManager.GetUserName());
ViewBag.IsSuper = SessionManager.SuperUser();
}
The bools are set properly and in the right order when I set up break points, but when I try to access them using the below code, I get a 'Cannot convert null to 'bool' because it is a non-nullable value type.'
#{
if((bool)#ViewBag.IsManager){
<li>#Html.ActionLink("Management", "Management", "Home",null, new { id = "managementLink" })</li>
}
}
There has to be something really simple I'm missing. Any help is greatly appreciated.
Based on your comment, #Dakine83, you should setup your ViewBag on the controller constructor method like so:
public class YourController : BaseController {
public YourController(){
}
}
The reason for that is because the Layout page is already rendered the time your action method has been called. The reason you have a null ViewBag.IsManager.
UPDATE: Use a base controller
public class BaseController : Controller {
public BaseController() {
ViewBag.IsManager = ADAccess.IsManager(SessionManager.GetUserName());
}
}
i hope this might work for you,please try it once
#Html.ActionLink("Management", "Management", "Home", new { id = false }, null);
Thanks