Objectify Query grandchildren relations - objectify

Suppose we have the following entities:
#Entity
#Cache
public class Site{
....
}
#Entity
#Cache
public class Page{
#Parent
private Key<Site> parent;
}
#Entity
#Cache
public class Comment{
#Parent
private Key<Page> parent;
}
What is the best way to query after the list of comments of a Page, having the Page id and Site id? I have tried .ancestor() method but this only accepts the Site entity,throwing a
java.lang.NullPointerException
at com.googlecode.objectify.impl.Keys.getMetadataSafe(Keys.java:61)
if I supply a Page entity instead. ancestor (site) is not good enough for this case, as I need the comments for a specific page. The only solution I can think about is to add a new attribute in the Comment entity Long pageId and #Index it and then use filter to get the comments of a page. Is there a better solution? Thank you!

Related

OneToMany Mapping Child Parent

Hi I am using Spring Boot app with MVC. I have two model classes Parent and Child. Parent to Child has OnetoMany Mapping. I have a form submit in which I'm passing few fields of child class, now what is happening when I bind the child class in the controller method is that it picks up the id of Parent class and binds it automatically to Child object in Controller.Please suggest what I am missing in here.
Following is the code for the same:
#PostMapping("/{id}/child")
public String editChildPOST(#PathVariable Long id,
Child child, Model model, BindingResult errors,
Principal principal) {
logger.info("editChildPOST: " + child.getId);
model.addAttribute("aaaa", aaaa);
model.addAttribute("bbbb", "bbbb");
return "redirect:/xxxx";
}
Following is the mapping in the parent Class :
class Parent{
#OneToMany(cascade= ALL, orphanRemoval=true)
#JoinColumn(name="parent_id")
private List<Child> child;
}
SO in debug mode if I try to check the value of child in Controller it shows Child Id as parent's Id although I haven't set Child Id anywhere in the form submit.

Webdriver: expose selector/by/location of existing element

The problem:
.Click()-ing a radio button webdriver element stales it(no control over the page that does this). The DOM element itself is still the same.
The goal:
I want to reset the existing webdriver element using its own original selector method so that it is no longer stale. I want a general solution that does not require knowing ahead of time how the element was found. I want to use the existing stale element to do the work. Ideal case would look something like this(using the following C# extension method just for sake of example):
IWebElement refreshedElement = driver.FindElement(staleElement.By());
The question:
Is there a way to expose the existing elements location? Is the 'address' of the element available anywhere? It doesn't even have to be the original method of addressing the element when it was found, I don't care about that. I'd just rather not have to make a subclass just to capture this information.
No, Selenium does not keep track of 'how' you found an element, and frankly I don't think that should be Selenium's responsibility.
I would wrap it into a new class, which inherits from RemoteWebElement, and has a method called RefindElement.
I might suggest considering adding the concept of a "Page Class". Basically, instead of adding the element to the test itself, I create a separate class that has methods that return elements.
For example, a login page would have three elements therefore 3 methods:
public class LoginPage
{
private IWebDriver driver { get; set; }
public CSCView_SalesAspx(IWebDriver driver) { this.driver = driver; }
public IWebElement Id { get { return driver.FindElement(By.Id("login_id")); } }
public IWebElement Pw { get { return driver.FindElement(By.Id("login_pw")); } }
public IWebElement SubmitBtn { get { return driver.FindElement(By.Id("submitBtn")); } }
}
Now all you have to do is instantiate the class then interact with the method. Your element should always be "fresh" since you're doing the lookup every time (without any extra work).
LoginPage loginPage = new LoginPage(driver);
loginPage.Id.SendKeys("myName");
loginPage.Pw.SendKeys("myPw");
loginPage.SubmitBtn.Click();
The best thing about this is if a page changes, instead of having to rewrite every test, you only change one page class and that fixes your broken tests.

Strongly typed form in MVC which maps to a different type?

When I specify form inputs with the #Html.TextBoxFor method, then the generated input element would not necessarily map to the type that is expected in the form's action method.
Let's say I have two classes:
public class HomeA
{
public int A { get; set; }
}
public class HomeB
{
public int B { get; set; }
}
HomeA is the model of my view. If a controller action expects HomeB, then I can't provide the necessary input element in a strongly typed manner in my form:
#using (Html.BeginForm())
{
#Html.TextBoxFor(model => model.A)
}
This form will obviously not map to HomeB's property.
The controller action should not expect HomeB.
Use one view model per action.
If you are sending a ViewModel of XYZ, then in general your ActionMethod takes a ViewModel of XYZ.
Thats my general thoughts anyways for consistency/readability.
However if it works for you, do it as long as the relation is there.
ASP.net MVC - One ViewModel per View or per Action?
As for the note on composition vs. inheritance check out
ASP.NET MVC Architecture : ViewModel by composition, inheritance or duplication?
Check out
http://lostechies.com/jimmybogard/2009/04/24/how-we-do-mvc/
You would create a HomeAB class that contains both a HomeA and HomeB
If you have to create and to show some items which belong to both classes A & B, you can design an interface and then inherit that interface. Or you can create another class AB which inherits from A & B.
Hope this helps!

Actionscript3 / LCCS: how to access property parent class protected var?

I would like to assign an event listener to a protected timer variable in the parent class.
I am working with Adobe LCCS, and created a BatonProperty
which implements Baton
Now, Baton has a protected timer variable declared like this, and for some reason, I am unable to get access to this _autoPutDownTimer, from a BatonProperty instance.
public function Baton()
{
super();
_autoPutDownTimer = new Timer(_timeout*1000, 1);
_autoPutDownTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
invalidator.addEventListener(Invalidator.INVALIDATION_COMPLETE,commitP roperties);
}
I would love to attach an eventlistener to it like this, but it seems I cannot, any tips are truly appreciated:
public var mybatonprop:BatonProperty;
mybatonprop= new BatonProperty();
mybatonprop.sharedID = "myBaton";
mybatonprop.subscribe();
mybatonprop.baton._autoPutDownTimer.addEventListener(TimerEvent.TIMER,countDown);
This gives the error : "actionscript attempted access of inaccessible property through a reference with static type" But it seems that property is not private, only protected, since it is declared like this
/**
* #private
*/
protected var _autoPutDownTimer:Timer;
If BatonProperty extends Baton, then just change the line:
mybatonprop.baton._autoPutDownTimer.addEventListener(TimerEvent.TIMER,countDown);
to
mybatonprop._autoPutDownTimer.addEventListener(TimerEvent.TIMER,countDown);
otherwise, make _autoPutDownTimer public, or follow #Jacob's answer.
Or for a third suggestion, as Baton is an Adobe class and you can't edit it, create your own class MyBaton which extends Baton, then do either of the two suggestions. (MyBaton will work everywhere Baton does)
protected means private except to descendants of the class. i.e. classes that inherit from the parent. It looks like your BatonProperty uses Baton via composition, not inheritance. And, from what I can tell, it seems like you're trying to access the _autoPutDownTimer from Baton/BatonProperty via a third class.
My recommendation, though would not be to add the event listener directly to the timer, but to dispatch an event from Baton in the onTimerComplete function
protected function onTimerComplete(event:TimerEvent):void {
....
dispatchEvent(new Event('putDownComplete'));
}
and
mybatonprop.baton.addEventListener('putDownComplete', onPutdownComplete);

Add eventlistener If the Object property is Updated or changed in Flex3, Air?

I am working in air application , i need to know how to add event listener when any object is updated, how can i implement this.
Example: i have Class name Vehicle, and child class are Car,Bus,Bikes,Scooter,..etc, child class also have many properties like color,model no,....etc
I have array collection and AddChild() method in Vehicle class by this, i will add, child class to the vehicle class.
I need a event listener which can trigger if any of the property is updated or changed in any of the child class property, how can i implements this in Flex3.
I need this for knowing, is there any update happen in the Object.
Thanks In Advance
One thing you can do is to make getters and setters for the properties instead of public vars and have your class extend EventDispatcher, if it does not already do so because it is extended from a MovieClip, like:
private var _vehicleName:String;
.
.
.
public function set vehicleName(value:String):void {
_vehicleName = value;
dispatchEvent(new VehicleEvent(VehicleEvent.propertyChange, "vehicleName"));
}
public function get vehicleName():String {
return _vehicleName;
}
(VehicleEvent being an extended class of Event with an extra string to signify which property changed)
Then you can add an eventlistener to the vehicles and they will dispatch events when the properties defined in this way change.
If you use an Array Collection for the vehicles and if you make the properties of the vehicles Bindable as Amarghosh suggests, then the array collection already should throw an Collection Event of the kind UPDATE. It also tells you which items (Vehicles) were updated an afaik also which properties were updated. But in general it is easier to directly bind to the property, like Amarghosh says.

Resources