In my development environment, I have added wrong data to my custom ItemType. Now I want to remove all data for that Type. Basically I want to truncate my ItemType table.
Run the below Impex (Change MyItemType with your ItemType)
$targetType=MyItemType
REMOVE $targetType[batchmode=true];itemtype(code)[unique=true]
;$targetType
You can also run SQL query from HAC, refer this post for more detail
I created an user whit XXX username from java code.
Because it was done with wrong permission and I can't see it from web interface, I delete directly from database.
After that if I try to create the same user I got the following exeception:
com.liferay.portal.GroupFriendlyURLException
What could gone wrong?
After some investigation I discover that:
Store user info in USER_ table
For each USER_ row there are a row in GROUP_ table, where personal sites url are
On user cration Liferay use username to generate a friendly url
this url have to be validated, and one rule is that must be unique
My problem was that I deleted the USER_ row only, so whe I tried to recreate deleted user control on GROUP_ table failed.
So I solved with:
GROUP_ row deletion (the one whit / on friendly url column)
Liferay restart
I have an application which has a table and when you click on an item in the table it fills in a group of textfields with its data (FieldGroup), and then you have the option of saving the changes I was wondering how would I save the changes the user makes to my postgres database. I am using vaadin and hibernate for this application. So far I have tried to do
editorField.commit() // after the user clicks the save button
I have tried
editorField.commit()
hbsession.persist(editorField) //hbsession is the name of my Session
and I have also tried
editorField.commit();
hbsession.save(editorField);
The last two ones give me the following error
Caused by: org.hibernate.SessionException: Session is closed!
Well, the first thing you need to realize is Vaadin differs from conventional request/response web framework. Actually, Vaadin is *event driven* framework very similar to Swing. It builds a application context from very first click of the user and holds it during whole website visit. The problem is there is no entry request point you can start hibernate session and no response point to close. There are tons of requests during a single click on button.
So, entitymanager-per-request pattern is completely useless. It is better to use one standalone em or em-per-session pattern with hibernate.connection_release after_transaction to keep connection pool low.
To the JPAContianer, it is not usable as far you need to refresh the container or you have to handle beans with relations. Also, I did not manage to get it working with batch load, so every reading of entry or relation equals one select to DB. Do not support lazy loading.
All you need is open EM/session. Try to use suggested patters or open EM/session every transaction and merge your bean first.
Your question is quite complex and hard to answer, but I hope these links help you get into:
Pojo binding strategy for hibernate
https://vaadin.com/forum#!/thread/39712
MVP-lite
https://vaadin.com/directory#addon/mvp-lite (stick with event driven pattern)
I have figured out how to make changes to the database here is some code to demonstrate:
try {
/** define the session and begin it **/
hbsession = HibernateUtil.getSessionFactory().getCurrentSession();
hbsession.beginTransaction();
/** table is the name of the Bean class linked to the corresponding SQL table **/
String query = "UPDATE table SET name = " + textfield.getValue();
/** Run the string as an SQL query **/
Query q = hbsession.createQuery(query);
q.executeUpdate(); /** This command saves changes or deletes a entry in table **/
hbsession.getTransaction().commit();
} catch (RuntimeException rex) {
hbsession.getTransaction().rollback();
throw rex;
}
I have a web application build in Django + Python that interact with web services (written in JAVA).
Now all the database management part is done by web-services i.e. all CRUD operations to actual database is done by web-services.
Now i have to track all User Activities done on my website in some log table.
Like If User posted a new article, then a new row is created into Articles table by web-services and side by side, i need to add a new row into log table , something like "User : Raman has posted a new article (with ID, title etc)"
I have to do this for all Objects in my database like "Article", "Media", "Comments" etc
Note : I am using PostgreSQL
So what is the best way to achieve this..?? (Should I do it in PostgreSQL OR JAVA ..??..And How..??)
So, you have UI <-> Web Services <-> DB
Since the web services talk to the DB, and the web services contain the business logic (i.e. I guess you validate stuff there, create your queries and execute them), then the best place to 'log' activities is in the services themselves.
IMO, logging PostgreSQL transactions is a different thing. It's not the same as logging 'user activities' anymore.
EDIT: This still means you create DB schema for 'logs' and write them to DB.
Second EDIT: Catching log worthy events in the UI and then logging them from there might not be the best idea either. You will have to rewrite logging if you ever decide to replace the UI, or for example, write an alternate UI for, say mobile devices, or something else.
For an audit table within the DB itself, have a look at the PL/pgSQL Trigger Audit Example
This logs every INSERT, UPDATE, DELETE into another table.
In your log table you can have various columns, including:
user_id (the user that did the action)
activity_type (the type of activity, such as view or commented_on)
object_id (the actual object that it concerns, such as the Article or Media)
object_type (the type of object; this can be used later, in combination with object_id to lookup the object in the database)
This way, you can keep track of all actions the users do. You'd need to update this table whenever something happens that you wish to track.
Whenever we had to do this, we overrode signals for every model and possible action.
https://docs.djangoproject.com/en/dev/topics/signals/
You can have the signal do whatever you want, from injecting some HTML into the page, to making an entry in the database. They're an excellent tool to learn to use.
I used django-audit-log and I am very satisfied.
Django-audit-log can track multiple models each in it's own additional table. All of these tables are pretty unified, so it should be fairly straightforward to create a SQL view that shows data for all models.
Here is what I've done to track a single model ("Pauza"):
class Pauza(models.Model):
started = models.TimeField(null=True, blank=False)
ended = models.TimeField(null=True, blank=True)
#... more fields ...
audit_log = AuditLog()
If you want changes to show in Django Admin, you can create an unmanaged model (but this is by no means required):
class PauzaAction(models.Model):
started = models.TimeField(null=True, blank=True)
ended = models.TimeField(null=True, blank=True)
#... more fields ...
# fields added by Audit Trail:
action_id = models.PositiveIntegerField(primary_key=True, default=1, blank=True)
action_user = models.ForeignKey(User, null=True, blank=True)
action_date = models.DateTimeField(null=True, blank=True)
action_type = models.CharField(max_length=31, choices=(('I', 'create'), ('U', 'update'), ('D', 'delete'),), null=True, blank=True)
pauza = models.ForeignKey(Pauza, db_column='id', on_delete=models.DO_NOTHING, default=0, null=True, blank=True)
class Meta:
db_table = 'testapp_pauzaauditlogentry'
managed = False
app_label = 'testapp'
Table testapp_pauzaauditlogentry is automatically created by django-audit-log, this merely creates a model for displaying data from it.
It may be a good idea to throw in some rude tamper protection:
class PauzaAction(models.Model):
# ... all like above, plus:
def save(self, *args, **kwargs):
raise Exception('Permission Denied')
def delete(self, *args, **kwargs):
raise Exception('Permission Denied')
As I said, I imagine you could create a SQL view with the four action_ fields and an additional 'action_model' field that could contain varchar references to model itself (maybe just the original table name).
I'm having trouble getting objects back out of SimpleDB using the simpleJPA persistance API. I have successfully installed all the jars and can persist objects no problem. However I cannot seem to retrieve objects using select queries - but weirdly I can get results using count queries. There are no errors or exceptions, the queries simply don't return any results. When I debug I can view the actual AWS Query that is being generated in the background by simpleJPA, and when I run this query against a domain it returns the expected results no problem.
I've included my Java code below, it should return me a list of all the users in my database.
Query query = em.createQuery("SELECT u FROM User u");
List<User> results = (List<User>)query.getResultList();
As I said I can persist objects and count them, so there isn't anything wrong with my entity manager or factory, its just returning empty lists. If you need any more information just ask,
Thanks in advance!
I never got to the bottom of this problem. In the end I started a new AWS project in Eclipse and re-added the JAR files, solving the issue.