PlantUML, how to add a FontColor for a column in entity - plantuml

I have this my PlantUML file
#startuml
' avoid problems with angled crows feet
skinparam linetype ortho
skinparam class {
FontColor<<generated>> #0000FF
}
entity "User" as users
{
*id : uuid <<generated>>
--
*email : text <<unique>>
password : text
}
entity "DishType" as dish_type {
*id : uuid <<generated>>
--
*name : text <<unique>>
image : text
}
entity "Dish" as dish {
*id : uuid <<generated>>
--
*name : text <<unique>>
image : text
menu_price : float
solo_price : float
dish_type_id : uuid <<FK>>
}
entity "Ingredient" as ingredient {
*id : uuid <<generated>>
--
*name : text <<unique>>
available : bool
}
dish "Many" --- "One" dish_type
dish "Many" --- "Many" ingredient
#enduml
So... I want that some fields like <<unique>> or <<generated>>, <<fk>> must be red, or yellow, whatever the color. I search like skinparam class but it works only with entity all fields, not only one field.
Can you help please. Thanks you :)

I don't think it's possible with skinparam since stereotypes don't apply to attributes. However, maybe the new stylesheets function will support something like this.
You could use a !function like the result below. It's not perfect, but might suit your needs. You could also do the same for the <<unique>> and other attributes.
#startuml
!function $generated($a)
!return "<color:#0000ff>" + $a + " <<generated>></color>"
!endfunction
' avoid problems with angled crows feet
skinparam linetype ortho
entity "User" as users
{
*$generated("id : uuid")
--
*email : text <<unique>>
password : text
}
entity "DishType" as dish_type {
*$generated("id : uuid")
--
*name : text <<unique>>
image : text
}
entity "Dish" as dish {
*$generated("id : uuid")
--
*name : text <<unique>>
image : text
menu_price : float
solo_price : float
dish_type_id : uuid <<FK>>
}
entity "Ingredient" as ingredient {
*$generated("id : uuid")
--
*name : text <<unique>>
available : bool
}
dish "Many" --- "One" dish_type
dish "Many" --- "Many" ingredient
#enduml

Related

id attribute in nested Java class mapped as MongoDb ObjectId()

Following structure:
#Document
public class Palace {
#Id
private String id;
private Location location;
// additional attributes, getter, setter
}
.
public class Location {
private String id;
// additional attributes, getter, setter
}
As far as I understand the concept of ObjectId, there can be only one ObjectId (_id) in a MongoDB document and it must be at the root level of the document. But when inserting data via Spring Boot 1.5.14 I get the followng structure:
{
"_id" : ObjectId("5b05387a8db58e0001d38851"),
"location" : {
"_id" : ObjectId("5ae712d1b2b197000132cd9b"),
}
}
My question is: Is this the expected behaviour in spring-data-mongo? I would have expected the following structure:
{
"_id" : ObjectId("5b05387a8db58e0001d38851"),
"location" : {
"id" : "5ae712d1b2b197000132cd9b",
}
}
If I annotate the Location id with #Field
public class Location {
#Field("id")
private String id;
// additional attributes, getter, setter
}
then the Document is saved as expected, but querying with repository method
getPalaceByLocationId()
won't give any results.
Some insights into id field. id field is treated a bit differently in spring-data-mongodb.
Check out the documentation.
Extending the documentation for your case, when you declare an id like this
public class Location {
private String id;
// additional attributes, getter, setter
}
It is stored as _id in database. You can cross check by looking into the database. The same is true when you annotate it with #Id
{
"_id" : ObjectId("5b31fad36a19cc45db205056"),
"location" : {
"_id" : ObjectId("5ae712d1b2b197000132cd9b")
}
}
5ae712d1b2b197000132cd9b is the id you had set using location.setId(). Internally it is converted to ObjectId and stored as _id.
But when you add #Field annotation, things change. Let's assume you add an annotation like this
#Field("id")
private String id;
Then the document looks like this in database.
{
"_id" : ObjectId("5b31fad36a19cc45db205056"),
"location" : {
"id" : "5ae712d1b2b197000132cd9b"
}
}
With this the problem is you cannot retrieve by id. Because when you write
findPalaceByLocationId or findByLocation_Id it(spring-data) tries to look for _id field which doesn't exist.
Only way around this is just use it like this
#Field
private String id;
or just
private String id;
This will create _id in database and you can do findByLocationId
I know it is a bit sketchy. But that is how it works.
And regarding
As far as I understand the concept of ObjectId, there can be only one
ObjectId (_id) in a MongoDB document and it must be at the root level
of the document.
that is incorrect.
A small info table regarding mapping
Field definition Resulting Id-Fieldname in MongoDB
String id _id
#Field String id _id
#Field('x') String id x
#Field('id') String id id (InAccessible)
#Id String x _id
#Field('x') #Id String x _id

Jena PrefixMapping: base namespace missing when model is a named model obtained from a dataset

This the code I am using to load OntModel to a Dataset as a Named Model. Then I try to retrieve the PrefixMapping for the same in two different ways:
public static void loadDatasetwithNamedModels(){
OntModel namedModel = null;
Dataset dataset = null;
dataset = TDBFactory.createDataset("./path/to/TDB_DIR");
namedModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
dataset.begin(ReadWrite.WRITE);
try{
namedModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
FileManager.get().readModel( namedModel, "./Path/to/OWLFile.owl");
dataset.addNamedModel("MyNamedModel", namedModel);
//Method 1
ModelGenerator.setModel(ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, namedModel)); // 1. returns the baseModel Namespace prefix mapping.
//Method 2
//ModelGenerator.setModel(ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, dataset.getNamedModel("MyNamedModel"))); // 2. Does not returns the baseModel Namespace prefix mapping.
ModelGenerator.setDataset(dataset);
ModelGenerator.getPrefixMap();
dataset.commit();
} finally {
dataset.end();
System.out.println("Database Ready..");
}
}
Method 1:- Using the OntModel variable in which the OWL file was read. In this case I get the desired output which contains the prefix mapping for the ontology URI denoted by Prefixes : and MyModel
Method 1 OUTPUT :
6
: http://www.semanticweb.org/ontologies/2013/8/MyModel#
rdfs : http://www.w3.org/2000/01/rdf-schema#
owl : http://www.w3.org/2002/07/owl#
xsd : http://www.w3.org/2001/XMLSchema#
MyModel : http://www.semanticweb.org/ontologies/2013/8/MyModel#
rdf : http://www.w3.org/1999/02/22-rdf-syntax-ns#
Method 2:- Using the OntModel variable obtained frem the dataset via dataset.getNamedModel("MyNamedModel");. In this case i fail to find the base prefixes.
Method 2 OUTPUT :
4
rdfs : http://www.w3.org/2000/01/rdf-schema#
owl : http://www.w3.org/2002/07/owl#
xsd : http://www.w3.org/2001/XMLSchema#
rdf : http://www.w3.org/1999/02/22-rdf-syntax-ns#
The function ModelGenerator.getPrefixMap() is as follows:
public static void getPrefixMap(){
Map<String, String> map = ModelGenerator.getModel().getNsPrefixMap();
System.out.println(map.size());
Set<String> set = map.keySet();
Iterator<String> it = set.iterator();
while(it.hasNext()){
String key = (String) it.next();
System.out.println("" + key + " : "+map.get(key) );
}
}

How to select a single Entity by key (low level java datastore API)

I'm a bit confused on how to create a "Key" object to select exactly 1 row of my Entity ("Customer").
My code :
Query query = new Query("Customer");
// **** how do I have to create this key ???
Key key = KeyFactory.createKey("Customer", 1);
// ****
FilterPredicate keyFilter = new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.EQUAL, key);
query.setFilter(keyFilter);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = datastore.prepare(query);
Entity customer = pq.asSingleEntity();
if (! (customer == null)) {
log.info("OK !");
}
else {
log.info("no customer found");
}
My result is always : "no customer found".
With the datastore viewer (I'm working locally) I can see 3 rows :
id/name = 1 email = "your email" name = "your name"
id/name = 2 email = "your email" name = "your name"
id/name = 3 email = "your email" name = "your name"
I want to select customer with id/name=1.
I've tried :
KeyFactory.createKey("Customer", 1);
and
KeyFactory.createKey("Customer", "your name");
but with no success.
When I do programmatically a search (asList) on "Customer" and I print the keys' values I see :
row 1 key = Customer("your name")/Customer(1)
row 2 key = Customer("your name")/Customer(2)
row 3 key = Customer("your name")/Customer(3)
The printable values of the keys are in the format : "Entity(name)/Entity(id/name)"
How can I create such key values in my code ?
On the javadoc I see only :
createKey("kind", id)
createKey("kind", "name")
The other methods require an ancestor, I've not created an ancestor ....
This is the code that I've executed to created the 3 rows (it has been executed 3 times) :
Key customerKey = KeyFactory.createKey("Customer", "your name");
Entity customer = new Entity("Customer", customerKey);
customer.setProperty("name", "your name");
customer.setProperty("email", "your email");
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(customer);
Thanks in advance !
Regards
Max
In other words, how do create a Key whose "toString" gives the following result ?
Code : log.info("customer KeyFactory.keyToString = "+KeyFactory.keyToString(key));
Output : INFO: customer KeyFactory.keyToString = Customer("your name")/Customer(1)
The creation of the Entities is not correct.
You dont have to create a key on your own.
If you create a Entity with a kind and keyname or ID parameter, a key will be created automaticlly out of the kind and the keyname or ID.
Entity customer = new Entity("Customer", "your name");
customer.setProperty("email", "your email");
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(customer);
That is all you need to create the Entity you want.
When you give a kind and a key, a child Entity will be created.
So you had created a Customer with "your name" who is a Customer with the ID 1.
To get the Entity with a key you just have to take the same parameters to create a key.
Key key = KeyFactory.createKey("Customer", "your name");
I would prefer to use get(), but i dont know what you want to do.
For Example to get the email of a Customer:
Entity e;
try {
e = datastore.get(key);
String myEmail= (String) e.getProperty("your email");
I think you want to use get() not query() when you have a Key.
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/DatastoreService#get(com.google.appengine.api.datastore.Key)
Let us assume that you have a Java entity class called Product and you wish to retrieve a unique record given its key i.e. ID
The method would look something like this:
public Product getProduct(Long id) {
//Get Persistence Manager
PersistenceManager pm = ...;
Key k = KeyFactory.createKey(Product.class.getSimpleName(), id);
Product product = null;
try {
product = pm.getObjectById(Product.class, k);
}
finally {
pm.close();
}
return product;
}
So in your example, I think you can replace Product with your class name. I guess your class name is Customer

Index the value of an Enum, not the string

Is it possible to index the value of an Enum instead of its string representation using Solrnet?
Say I have to following enum:
[Serializable]
[Flags]
public enum Gender
{
Male = 0,
Female = 1
}
and add a solr attribute to the Gender property of a User class:
[SolrField("gender")]
public virtual Gender Gender { get; set; }
If I index the entity using:
solr.Add(user)
then it will index 'Male' as gender instead of 0. Is it possible to have it index 0 instead?
Edit: I'd prefer not to add an extra property for this, like Ondrej proposes.
You can do this by implementing ISolrFieldSerializer. If the type IsEnum, serialize by casting to int. Otherwise delegate to DefaultFieldSerializer. Use the other field serializers for reference.
Hooking up your field serializer depends on the chosen IoC container, check the container's documentation.
Try this:
[SolrField("gender")]
public int GenderAsInt
{
get { return (int) Gender; }
set { Gender = (Gender) value; }
}
public virtual Gender Gender { get; set; }
Also note that declaring your enum as [Flags] doesn't make much sense:
There will hardly be anyone both Male and Female
Male will be interpreted as the default in respect to the current values of enum fields

google datastore many to one references

So i have two model classes:
class Dog(db.model):
dogName = StringProperty()
dogBreed = StringProperty()
class Cat(db.model):
catName = StringProperty()
catBreed = StringProperty()
and then i have a third model class to hold all the pictures
class Images(db.model):
imageReference = ReferenceProperty(*Animal*, collection_name = 'allImages')
imageURL = StringProperty()
Animal is either a Dog or a Cat. Obviously this does not compile.
Now my question is: Is there a way I can put Cat pictures in with Dog pictures? Or do I need to create more models like this:
class DogImages(db.model):
imageReference = ReferenceProperty(Dog, collection_name = 'allImages')
imageURL = StringProperty()
class CatImages(db.model):
imageReference = ReferenceProperty(Cat, collection_name = 'allImages')
imageURL = StringProperty()
You could use PolyModel:
class Animal(polymodel.PolyModel):
name = db.StringProperty()
breed = db.StringProperty()
class Dog(Animal):
pass
class Cat(Animal):
pass
Now you can have a ReferenceProperty that references Animals, and either Dogs or Cats will be permitted.
However, you don't have any properties that are specific to each type of animal - why not just have a regular Animal model, add a property indicating what species it is, and skip the separate models entirely?

Resources