/** Form to create a new actor (available from Admin menu). */ @Restrict({@Group(IMafConstants.ACTOR_EDIT_ALL_PERMISSION)}) public Result create() { // construct the form Form<ActorFormData> actorForm = formTemplate; // add the custom attributes default values this.getCustomAttributeManagerService().fillWithValues(actorForm, Actor.class, null); return ok(views.html.core.actor.actor_new.render(actorForm, ActorDao.getActorTypeActiveAsVH())); }
/** * Form to edit an actor (available from the details of an actor). * * @param id the actor id */ @With(CheckActorExists.class) @Dynamic(IMafConstants.ACTOR_EDIT_DYNAMIC_PERMISSION) public Result edit(Long id) { // get the actor Actor actor = ActorDao.getActorById(id); // construct the form Form<ActorFormData> actorForm = formTemplate.fill(new ActorFormData(actor)); // add the custom attributes values this.getCustomAttributeManagerService().fillWithValues(actorForm, Actor.class, id); return ok( views.html.core.actor.actor_edit.render( actor, actorForm, ActorDao.getActorTypeActiveAsVH())); }
/** Process the save of an actor (create and edit cases). */ @Dynamic(IMafConstants.ACTOR_EDIT_DYNAMIC_PERMISSION) public Result save() { // bind the form Form<ActorFormData> boundForm = formTemplate.bindFromRequest(); if (boundForm.hasErrors() || this.getCustomAttributeManagerService().validateValues(boundForm, Actor.class)) { if (boundForm.data().get("id") != null) { // edit case // get the actor Long id = Long.valueOf(boundForm.data().get("id")); Actor actor = ActorDao.getActorById(id); return ok( views.html.core.actor.actor_edit.render( actor, boundForm, ActorDao.getActorTypeActiveAsVH())); } else { // new case return ok( views.html.core.actor.actor_new.render(boundForm, ActorDao.getActorTypeActiveAsVH())); } } ActorFormData actorFormData = boundForm.get(); // check the uid is not already used by another actor if (actorFormData.uid != null && !actorFormData.uid.equals("")) { Actor testActor = ActorDao.getActorByUid(actorFormData.uid); if (testActor != null) { // edit case if (actorFormData.id != null) { if (!testActor.id.equals(actorFormData.id)) { boundForm.reject("uid", Msg.get("object.actor.uid.invalid")); Actor actor = ActorDao.getActorById(actorFormData.id); return ok( views.html.core.actor.actor_edit.render( actor, boundForm, ActorDao.getActorTypeActiveAsVH())); } } else { // new case boundForm.reject("uid", Msg.get("object.actor.uid.invalid")); return ok( views.html.core.actor.actor_new.render(boundForm, ActorDao.getActorTypeActiveAsVH())); } } } Actor actor = null; if (actorFormData.id != null) { // edit case actor = ActorDao.getActorById(actorFormData.id); actorFormData.fill(actor); actor.update(); Utilities.sendSuccessFlashMessage(Msg.get("core.actor.edit.successful")); } else { // new case actor = new Actor(); actorFormData.fill(actor); actor.save(); Utilities.sendSuccessFlashMessage(Msg.get("core.actor.new.successful")); } // save the custom attributes this.getCustomAttributeManagerService().validateAndSaveValues(boundForm, Actor.class, actor.id); return redirect(controllers.core.routes.ActorController.view(actor.id)); }