Auto populate table after portlet is deployed in liferay - database

I need a way to automatically populate a table created by the service builder of a portlet that is deployed in liferay. How can I accomplish that? I was thinking of a startup hook, but I won't be able to access the service of the particular portlet. So is there a way to populate it through the portlet itself ?

If you manage to not make the changes destructive (e.g. be careful not to populate on every startup) you can do it in a StartupAction (or startup hook). You can add this hook to your portlet project - this works just fine. Alternatively you could declare a hook to be dependent on a portlet (or vice versa) in liferay-plugin-package.properties - this will make the services available. But for this purpose, I'd just package everything in one portlet plugin.
If you might have destructive changes in there, an Upgrade Action will be a safer bet: This is guaranteed to run only once.
For examples see the old sevencogs sample (let me know if you need pointers, then I'll get them out)
Update: To include such a hook in a portlet project, add WEB-INF/liferay-hook.xml with the following content (or use Liferay IDE's wizard to just add a hook to the project)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>
Also, create WEB-INF/src/portal.properties with the following option
application.startup.events=com.example.MyStartupAction
and, of course, create the mentioned startup action, extending com.liferay.portal.kernel.events.SimpleAction

Try by deleting an entry from servicecomponent table. And redeploy your portlet.
delete FROM servicecomponent where buildNamespace="<your table namespace>"

Related

How can I create a Netlify CMS collection file upon the submission of a Netlify Form?

I currently have a GatsbyJS app that is using Netlify CMS (NCMS) for content management and Netlify via GitHub for hosting/deployment.
I would like to build a very simple order form system, but I would like to use JSON files and NCMS collections to represent the data because I will have very minimal data requirements and I would like the ability to have the data administered entirely through NCMS.
For example, I have a Products collection and an Orders collection. Products is using a JSON extension and contains JSON files that represent each product. Everything is looking good there. For Orders, I want to be able to create new entries from NCMS OR from an order form in my app.
Creating Orders entries in NCMS should be simple enough using the relation widget to incorporate a Products entry into each order. What I'm trying to figure out is how I can create JSON files in my filesystem (repo) upon form submission. I assume this is possible in some way with GitHub webhooks because NCMS is doing this when you create files in their system.
Can I, using some combination of Netlify's Forms API, Netlify Functions and/or GitHub webhooks, create a file in my GitHub repository when a user submits a Netlify Form in my app?
If this isn't possible, my follow up strategy would be to save Orders data in a MongoDB database. I do not have any experience yet with Mongo, but I know it's based around a "flat" data format using a JSON like syntax. Could I possibly save my order data in a Mongo collection upon submission via a Netlify Lambda function, then trigger a build via Netlify, and in my app pull in Mongo data at build time, and somehow create a file for each order object, perhaps via Gatsby's API?
My last resort would be to set up an admin area of my app where orders could be viewed, modified, and deleted. I'd prefer to avoid this because a) I do not have Netlify Pro services and thus do not have access to password protected site access (though I'm not sure how NCMS utilizes Identity and is able to avoid the premium plan?), and b) I would like all data administration to occur through the same platform (Netlify CMS).
You can definitely do this with Netlify Form, Function & Github API. I've done something similar for one of my gatsby sites, where form data is submitted directly to a Netlify function.
If you'd like to take advantage of Netlify Form's features like spam prevention & email notification, I think it'll look something like this:
Set up your Netlify Form
Set up a Netlify function that listens to the submission-created event. In the body of the request, you'll find a payload object that contains the form data, as well as info about your site (in case you have a bunch of them).
Netlify has a package that really ease up the development process.
Trigger a call to Github API to either create a file for that submission or update an existing file that contains all submissions.
At this point, you can set up netlifyCMS to read the content of that folder / file & allow admin to review / modify the submissions.
Hope it helps!

Cakephp3 handle authorization as a plugin

I've been working on cakephp3 for a while now. I've always used Cakephp's Auth component for authorization and authentication purpose.
I follow the very conventional procedure every time, like loading the component, adding isAuthorized function in controllers and defining allowMethods etc.
But now what I want is to develop my own plugin for this purpose, just using Cake's Auth component. So that i can reuse the plugin in all my future projects, also i want it to be like plug and play. Like You enable it, add few settings and your User management is done.
I know that how migrations work so I can add users table via migration every time. (Just an idea)
The thing I don't get right now is how to make everything separate from the core app? Like everything is done via plugin and nothing is added to every controller of the app.
Hope I'm clear about what I want to achieve.
Update: I know there is a whole list of third party Auth plugins. But I want to develop my own so i just need the idea of how things work.
Any solutions to my problem would save my day.

How to build sets of entity records using Breeze and local storage

I'm trying to create an off-line data collection app, using AngularJS.
I think, adding Breeze.js should help with saving and querying data to and from the browser local storage:
1) present the user with angular data entry form
2) when the "save" button is clicked - create a new Breeze entity and store it locally
3) the next time this form is used - create a second entity, and add/save it as a part of the same collection
I was wandering if anyone have tried to do something similar and could give me some pointers of how this is done.
I think it's viable and these links should help you to get started:
http://www.breezejs.com/documentation/querying-locally
You also might want to check this Angular sample aswell:
http://www.breezejs.com/samples/todo-angular
One caveat you have to have in mind is that Breeze will need to load the model's metadata from somewhere. Typically you hit a Web API asynchronously and get the metadata from there. However, on your particular scenario you should give a look at trying to load your metadata from a script file. Here's an how-to and discussion about it:
http://www.breezejs.com/documentation/load-metadata-script

How to create a custom module from Webforms in Drupal 7

I have a form that I am aiming to submit to paypal payment.
I have tried several options like the Paypal API and the like but I can't seem to get the hang of it since the requirement of what I am doing is pretty simple.
Right now I have a form and I am using Webforms to build it. I am well aware that webforms has its default value for action attribute which is not so easy to alter.
Also, the names for the inputs appear to be something like:
name="submitted[last_name]"
To be direct, I would like to change the actions url of the webform and then the field names from to simply name="last_name"
Is there a simple way to do it? If there is, I would appreciate your suggestion.
Also, if what I assume based on my reading that it is not possible, I have read in this question (Using Hook_form_alter on webform submitted values) that I can create a custom module based on webform and make the changes there. The problem is that I am new to drupal and I am still trying to understand how to make things work and I have no idea how to start or create the custom module based on webforms. Is it just simply copying the whole files in webforms then replace all occurences of webforms to my custom module name?
You dont create a module from webforms, instead the usual practice is to hook in to specific form from another module.
Basicly you need 1 folder and 2 files in there, eg mymodule folder and mymodule.info + mymodule.module . Good place to place those would be sites/all/modules/custom/ under your installation directory.
Read the description about .info file at https://www.drupal.org/node/542202
You can connect to webforms in many ways but the standard way in most form tampering cases start with hook_form_alter. Your module could start with something like this
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id){
/* find and tamper with $form here
install devel and then uncomment the following */
//dpm($form);
}

Is there a way a method can be triggered or run during a salesforce package installation process?

I would want to do this to run post installation setup process like adding custom data that is required for the application to run.
One option I am aware of is to Write Installation and Setup instructions for users. Create visualforce page and include a button on this page. Redirect user to this page as the process of Installation and ask the user to click the button.
I only wanted to know If there was a more elegant way to solve the problem and if there is a way to call a method during the installation process.
Salesforce has recently implemented the ability to execute scripts (as Apex) during package Install / Uninstall:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_install_handler.htm
No, we can't have a post installation script for the app. What you are saying is best solution, just keep a custom setting to flag, if initial setup is not done, then redirect to the setup page first, other wise do the normal work.
My question would be revolving around why you need custom data for the app to run? One of the things Salesforce look for when doing a security review of your code and the unit tests you have is to check to see if you are requiring data in your org as this is bad practice. Note that if your app is requiring specific data to run then it cannot be tested properly as the data will not be in the org when running the tests on install.
What is the data you are requiring? Could it be stored in an xml like static resource file or something similar for you to load and parse as it is needed?
Paul

Resources