Resteasy: difference between these two paths - resteasy

Resteasy: difference between these two paths
#Path("/a")
public class Resource1
{
#GET
#Path("/b")
public Response get() {}
}
vs
#Path("/a")
public class Resource1
{
#GET
#Path("b")
public Response get() {}
}
Note that the difference is in the b. SOF wants me to type more, so I'm typing more.

From the documentation:
For an annotated method the base URI is the effective URI of the containing class. For the purposes of absolutizing a path against the base URI , a leading '/' in a path is ignored and base URIs are treated as if they ended in '/'
So in short: Both examples are effectively the same.

Related

how to get range class of objectProperty by its domain class in owlapi?

In my project, I'd like to get all the range class related to the given class by an restricted(somevaluefrom or allvalues from) objectproperties. I can get the restricted subclassofAxioms expressions including the given class, but how can I get the range class in these expressions? In other word, how can I get all the related classes to the given class excluding inherited subclass.
For example:
public static void printSubClassOfAxioms(OWLOntology ontology,OWLReasoner reasoner,OWLClass owlClass){
for(OWLSubClassOfAxiom ax:ontology.getSubClassAxiomsForSubClass(owlClass)){
OWLClassExpression expression=ax.getSuperClass();
System.out.println(ax);
System.out.println(expression);
}
}
The results are:
SubClassOf(<#FourCheesesTopping> <#CheeseTopping>)
SubClassOf(<#FourCheesesTopping> ObjectSomeValuesFrom(<#hasSpiciness> <#Mild>))
SubClassOf(<#FourCheesesTopping> ObjectAllValuesFrom(<#hasCountryOfOrigin> #Country>))
How can I just get the range classes #Country and #Mild
Thank you for your attention!
Write an OWLObjectVisitor and override the visit(OWL... Type) for the restrictions you're interested in. At that point,
type.getFiller()
will yield the class you're after.
Examples are in the documentation: https://github.com/owlcs/owlapi/wiki/Documentation
public class RestrictionVisitor extends OWLClassExpressionVisitor {
#Override
public void visit(#Nonnull OWLObjectSomeValuesFrom ce) {
// This method gets called when a class expression is an existential
// (someValuesFrom) restriction and it asks us to visit it
}
}

Localization in MEF: export attribute does not support a resource (WPF - C#)

I have an application with a plugin architecture using MEF. For every exported part there is an attribute with the part's name, and I want to have the names translated, because I use these strings to display the available parts in ListBoxes (or the like).
So, I tried to set the 'Name = Strings.SomeText" in the [Export] annotation, but I get the following error:
"An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type"
Is there a solution to this? I find the use of the Metadata very useful (I do lazy loading) and I would not want to redesign everything just to get a few texts translated.
Any ideas? Thanks.
Unfortunately you can't directly provide the translated text to the attributes because an attribute can only contain data that is known at compile time. So you will need to provide some compile time constant value that you can later use to look up the translated test.
One solution would be to pass the resource name to the attribute. Then when you want to display the translated text you grab the resource name, look up the text in the resources and display the result.
For instance your attribute could look something like:
[Export(Name = "SomeText")]
public class MyExport
{
}
Then when you want to display the string you load the resources from the assembly that defines the export and you extract the actual text from the loaded resources. For instance like this (as borrowed from another answer):
var assembly = typeof(MyExport).Assembly;
// Resource file.. namespace.ClassName
var rm = new ResourceManager("MyAssembly.Strings", assembly);
// exportName contains the text provided to the Name property
// of the Export attribute
var text = rm.GetString(exportName);
The one obvious drawback about this solution is that you lose the type-safety that you get from using the Strings.SomeText property.
--------- EDIT ---------
In order to make it a little easier to get the translated text you could create a derivative of the ExportAttribute which takes enough information to extract the translated text. For example the custom ExportAttribute could look like this
public sealed class NamedExportAttribute : ExportAttribute
{
public NamedExportAttribute()
: base()
{
}
public string ResourceName
{
get;
set;
}
public Type ResourceType
{
get;
set;
}
public string ResourceText()
{
var rm = new ResourceManager(ResourceType);
return rm.GetString(ResourceName);
}
}
Using this attribute you can apply it like this
[NamedExport(
ResourceName = "SomeText",
ResourceType = typeof(MyNamespace.Properties.Resources))]
public sealed class MyClass
{
}
Finally when you need to get the translated text you can do this
var attribute = typeof(MyClass).GetCustomAttribute<NamedExportAttribute>();
var text = attribute.ResourceText();
Another option is to use the DisplayAttribute

Can a route begin with a variable?

This DTO
[Route("/{Module}/{Name}")]
public class ViewEntityList {
public string Module { get; set; }
public string Name { get; set; }
}
causes my app to error on startup with
RestPath '/{Module}/{Name}' on Type 'ViewEntityList' is not Valid
I could change the route to begin with a literal (e.g. /Entity/{Module}/{Name}) but it's not what I want; besides, my URLs are starting to look excessively long and un-REST-like.
Is it possible to begin a route with a variable? If not, is there another way to map any route with two parts to a specific DTO?
I always do following:
//Configure User Defined REST Paths
Routes
.Add<DTO1>("/service/function/{argument}")
.Add<DTO2>("/service/commonsegment/{Function*}")
the mapping for DT1 is the "basic" mapping, one URL correspond to a DTO.
in DTO2 you will need a key called "Function" that will give you the name of the first "non-common" segment of the URL, any other segments preset in the URL will be mapped to your DTO2 if possible (if there is a matching property on it). This way you're open to new functions/arguments without changing the web server itself, only the backing implementation (that could/shlould be located on a external dll).
I hope this helps.

Parameter must be an entity type exposed by the DomainService?

Trying to implement a domain service in a SL app and getting the following error:
Parameter 'spFolderCreate' of domain method 'CreateSharePointFolder' must be an entity type exposed by the DomainService.
[EnableClientAccess()]
public class FileUploadService : DomainService
{
public void CreateSharePointFolder(SharePointFolderCreate spFolderCreate)
{
SharePointFolder spf = new SharePointFolder();
spf.CreateFolder_ClientOM(spFolderCreate.listName, spFolderCreate.fileName);
}
[OperationContract]
void CreateSharePointFolder(SharePointFolderCreate spFolderCreate);
[DataContract]
public class SharePointFolderCreate
{
private string m_listName;
private string m_fileName;
[DataMember]
public string listName
{
get { return m_listName; }
set { m_listName = value; }
}
[DataMember]
public string fileName
{
get { return m_fileName; }
set { m_fileName = value; }
}
}
So am I missing something simple here to make this all work?
It may be that the framework is inferring the intended operation because you have the word "Create" prefixing the function name (CreateSharePointFolder). Details of this behaviour can be found here
Although that is all fine for DomainServices and EntityFramework, following the information in that article, it can be inferred that methods beginning "Delete" will be performing a delete of an entity, so must accept an entity as a parameter. The same is true for "Create" or "Insert" prefixed methods. Only "Get" or "Select" methods can take non-entity parameters, making it possible to pass a numeric id (for example) to a "Get" method.
Try changing your method name temporarily to "BlahSharePointFolder" to see if it is this convention of inferrance that's causing your problem.
Also, as there is no metadata defined for your SharePointFolderCreate DC, you might need to decorate the class (in addition to the [DataContract] attribute) with the [MetadataType] attribute. You will see how to implement this if you used the DomainServiceClass wizard and point to an EF model. There is a checkbox at the bottom for generating metadata. Somewhere in your solution.Web project you should find a domainservice.metadata.cs file. In this file, you will find examples of how to use the [MetadataType] attribute.
For the RIA WCF service to work correctly with your own methods, you need to ensure that all entities existing on the parameter list have at least one member with a [Key] attribute defined in their metadata class, and that the entity is returned somewhere on your DomainService in a "Get" method.
HTH
Lee

App Engine - Query using a class member as parameter

I have a simple class, relevant details below:
#PersistenceCapable(identityType = IdentityType.APPLICATION)
public class SimpleCategory implements Serializable{
...
public static enum type{
Course,
Category,
Cuisine
}
#Persistent
public type t;
...
}
I am attempting to query all SimpleCategory objects of the same type.
public SimpleCategory[] getCategories(SimpleCategory.type type) {
PersistenceManager pm = PMF.get().getPersistenceManager();
try{
Query q = pm.newQuery(SimpleCategory.class);
q.setFilter("t == categoryType");
q.declareParameters("SimpleCategory.type categoryType");
List<SimpleCategory> cats = (List<SimpleCategory>) q.execute(type);
...
}
This results in a ClassNotResolvedException for SimpleCategory.type. The google hits I've found so far recommended to:
Use query.declareImports to specify the class i.e. q.declareImports("com.test.zach.SimpleCategory.type");
Specify the fully qualified name of SimpleCategory in declareParameters
Neither of these suggestions has worked. By removing .type and recompiling, I can verify that declareParameters can see SimpleCategory just fine, it simply cannot see the SimpleCategory.type, despite the fact that the remainder of the method has full visibility to it.
What am I missing?
You elided (...) whether public static enum type itself is declared #PersistenceCapable. If it isn't, that might explain why the query parser isn't able to resolve a reference to the type class.
Something that has seemed to work for me is writing the query string using an implicit parameter and not using the declareParameters() method.
q.setFilter("t == :categoryType");
List<SimpleCategory> cats = (List<SimpleCategory>) q.execute(type)

Resources