Can an utils.py file be used in more than one module? - python-packaging

I am working in a somewhat substantial application, and there is some common logic that I've put in an utils.py (you can tell where this is going).
I am not sure where I should put utils.py, or if I should have more than one copy of it, or if I should install it as a module itself.
Consider this simplified application layout from realpython.com
helloworld/
│
├── helloworld/
│ ├── __init__.py
│ ├── runner.py
│ ├── hello/
│ │ ├── __init__.py
│ │ ├── hello.py
│ │ └── helpers.py
│ │
│ └── world/
│ ├── __init__.py
│ ├── helpers.py
│ └── world.py
│
└── README.md
You have the two main files hello.py and world.py, and there is some hello.py specific helper functions in the adjacent helpers.py.
However, what if there is a substantial amount of logic that is common to both helpers.py; say a sqlalchemy connection or some dataclasses that are endemic across the application.
To make the conversation concrete, suppose I have a dataclass User that is needed pretty much everywhere. Where should I put the file that defines User so that it is available in all the other .py files?
On the one hand I understand the idea behind a directory tree (it's not a tree if the leafs all import utils.py). But what's the alternative? To copy that logic everywhere?

Related

How do I import a file from the test directory to use in a lib file?

In an attempt to figure out an issue, I realized that my file sqflite_datasource.dart calls for something that is only found in the file sqflite_datasource_test.mocks.dart. I am trying to import the file sqflite_datasource_test.mocks.dart as a package to the file sqflite_datasource.dart so that I don't get the error anymore.
I've tried the following and they don't work:
import 'package:rethink_chat/test/data/sqflite_datasource_test.mocks.dart';
import '../test/data/sqflite_datasource_test.mocks.dart';
They both have red squiggly lines and if I hover over them, it asks if I want to create the file. It's not finding that it already exists.
These are the files I have:
│ ├── data
│ │ └── datasources
│ │ ├── datasource_contract.dart
│ │ └── sqflite_datasource.dart
│ ├── main.dart
│ └── models
│ ├── chat.dart
│ └── local_message.dart
├── test
│ ├── data
│ │ ├── sqflite_datasource_test.dart
│ │ └── sqflite_datasource_test.mocks.dart
│ └── widget_test.dart
I'll add the whole reason I'm trying this is because I'm having this issue. I determined update is being found in the test file, I think because I imported the mocks file there (they're both within the test folder). But the test file calls a function in sqflite_datasource.dart that uses update, which I haven't imported the mocks file to. So I'm trying to import the mocks file there because it has the information on what update is. I'm a total beginner so please bear with me, it's probably a very simple solution.
Edit: I'm so confused. Some of the functions in sqflite_datasource.dart that use things other than "update" but similar, like "query" and "insert" work just fine. So I have no idea why "update" isn't working.

How to not group folders and files in the sidebar of VS Code but order everything alphabetically?

I have the following file structure in VS Code:
├── 01-getting-started
│ ├── 01-quickstart.mdx
│ ├── 02-setup-prisma
│ │ ├── 01-add-to-an-existing-project.mdx
│ │ ├── 02-start-from-scratch-sql-migrations.mdx
│ │ ├── 03-start-from-scratch-prisma-migrate.mdx
│ │ └── index.mdx
│ ├── 03-tutorial.mdx
│ └── index.mdx
This is how the files are getting rendered in the VS Code sidebar:
There's an issue because the 02-setup-prisma folder alphabetically comes after the 01-quickstart.mdx file but because folders are displayed before files, the alphabetical order of sidebar items isn't retained.
Is it possible to make it so that the alphabetical order of sidebar items is retained, even though that would mix files and folders?
Look at the
Explorer> Sort Order
setting. Try the mixed option which will sort alphabetically interleaving files and folders.

Is there a way to point a fallback intent to an actual intent in api.ai?

Bear with me on this one. I will try to explain in the simplest way possible. I have built a chatbot using API.AI. The tree below is a simple and rough representation of how the flow goes. First 2 levels are straightforward, it just asks simple questions then it branches out to different paths. As you can see also, that the endpoint is all the same.
The question here is that with a common endpoint and having multiple yes/no fallback intents, is there a way to link the fallback intents to one common intent?
Get name
└── Get email address
├── [johndoe#email.com]
└── Does not give email address
├── Know more about person
│ ├── About short description
│ │ └── Dont want to know more
│ │ ├── Read more
│ │ └── Want to connect with person?
│ │ ├── Show email address
│ │ └── Goodbye
│ ├── Coding short description
│ │ └── Dont want to know more
│ │ ├── Read more
│ │ └── Want to connect with person?
│ │ ├── Show email address
│ │ └── Goodbye
│ ├── Achievements short description
│ │ └── Dont want to know more
│ │ ├── Read more
│ │ └── Want to connect with person?
│ │ ├── Show email address
│ │ └── Goodbye
│ └── Skills short description
│ │ └── Dont want to know more
│ │ ├── Read more
│ │ └── Want to connect with person?
│ │ ├── Show email address
│ │ └── Goodbye
└── Want to connect with person?
├── Show email address
└── Goodbye
I assume by the structure you've given that you're using FollowUpIntents, one way to group multiple intents to one fallback intent is using a contextOut that's the same for all the endpoints you'd like to match the fallback to.
FollowUp intents actually construct their flow with contexts in the same way, however, you can do this yourself too ofcourse.
so in the following intents:
│ ├── Coding short description
│ ├── Achievements short description
│ └── Skills short description
You simply set the contextout of these intents to something like "contextFallback".
In:
Dont want to know more
You simply set the contextIn as "contextFallback". This way, every time you trigger one of the contexts that set the context out, you can trigger and branch to the "Dont want to know more" intent. Resulting in one intent (instead of the 4 intents that do the same as per your example)
I hope I understood your question properly, otherwise I'll edit my answer.

custom-sql on existing tables in liferay

I need to make custom queries to the liferay database including JOIN, etc.
My research took me to use the Service Builder strategy.
But when I read about the service builder, you need to define entities in the service.xml file. I do not need an entity, I am willing to use existing entities, for example JournalArcticle, etc.
I would appreciate if someone could direct me to the correct way to go.
The Query I need to use:
SELECT ja.*
FROM liferay.journalarticle ja
INNER JOIN liferay.assetentry ae
ON ja.resourcePrimKey = ae.classPK
INNER JOIN liferay.assetentries_assettags ae_at
ON ae.entryId = ae_at.entryId
INNER JOIN liferay.assettag tags
ON ae_at.tagId = tags.tagId
where tags.name = "actualités de recherche"
;
JournalArticle, assetentries_assettags, AssetTag, AssetEntry are all legacy liferay entities.
I am using liferay 6.1.1-GA2
I read that:
http://www.liferay.com/fr/documentation/liferay-portal/6.1/development/-/ai/define-object-relational-maps-liferay-portal-6-1-dev-guide-en
and that:
http://www.liferay.com/fr/web/sten.martinez/blog/-/blogs/using-a-legacy-db-with-service-builder
Basicaly, I follow the service builder rule and adapt it to maven environment.
Colored version of the post: http://blog.melard.fr/post/123556374437/liferay-implementing-your-custom-service-using
Environnement
------------------------------------
liferay: liferay-portal-6.1.1-ce-ga2
------------------------------------
PAY ATTENTION
If you define a variable hot.deploy.listeners in your portal-ext.properties file, be sur to add the com.liferay.portal.deploy.hot.SpringHotDeployListener class or you might get a BeanLocator is not set error.
I’ve been studying the way to implement a custom service using custom sql based on existing entities.
Case study
I need to retrieve the last version of JournalArticles using pagination adn tag name.
References
blog
Get last version of last journal articles
The answer from that blog entry is to retrieve all the articles and then for each article check if it is the last version of the article using that method:
if(JournalArticleLocalServiceUtil.isLatestVersion(groupId,journalobj.getArticleId(),journalobj.getVersion())){
// here logic will come or you can create another list to add those articles with latest version
}
Determine latest version of Web Content in Liferay
This is another solution, worse than the one mentionned before as it retrieve all the articles and then for each article, check if the articleId has been already loaded.
List articles = JournalArticleLocalServiceUtil.getStructureArticles(GROUPID, STRUCTUREID);
ListIterator it = articles.listIterator();
List checkedArticleIds = new ArrayList();
while (it.hasNext()) {
JournalArticle article = it.next();
if (checkedArticleIds.contains(article.getArticleId())) {
continue; // previous article version already checked
}
JournalArticle articleLastVersion = JournalArticleLocalServiceUtil.getLatestArticle(GROUPID, article.getArticleId());
checkedArticleIds.add(article.getArticleId());
System.out.println("Added articleId " + article.getArticleId() + " with version " + article.getVersion());
}
Find Liferay Latest Journal Atticles By Tag Name
public List getArticlesByTags(long groupId, String tagName)
throws PortalException, SystemException {
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
long[] anyTagIds = AssetTagLocalServiceUtil.getTagIds(groupId, new String[]{"alllocation", tagName});
assetEntryQuery.setAnyTagIds(anyTagIds);
List assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
List journalArticleList = new ArrayList();
for (AssetEntry ae : assetEntryList) {
JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil
.getJournalArticleResource(ae.getClassPK());
JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(groupId,
journalArticleResourceObj.getArticleId());
journalArticleList.add(journalArticleObj);
}
return journalArticleList;
}
The first article entries are not possible because they retrieve all the articles in the database and then process them in order to get the latest versions of each article. It is possible for small entry sets. But when you get to thousands of articles, it will get very slow.
I like better the third article because you only get a limited amount or articles
Implement a custom service using Service Builder
I wanted to use a single method to get last article version by tag name using an SQL Query and let the database handle the joins
SELECT ja.*
FROM JournalArticle as ja
JOIN (
SELECT SUBSTRING_INDEX(GROUP_CONCAT(uuid_ ORDER BY version DESC),',',1) AS uuid_LastVersion
FROM JournalArticle ja
INNER JOIN assetentry ae
ON ja.resourcePrimKey = ae.classPK
INNER JOIN AssetEntries_AssetTags ae_at
ON ae.entryId = ae_at.entryId
INNER JOIN AssetTag tags
ON ae_at.tagId = tags.tagId
where tags.name = ?
GROUP BY articleId
ORDER BY articleId DESC
) as uuids
ON ja.uuid_ = uuids.uuid_LastVersion
After doing a lot of research, I found out that Service Builder was the way to go. I read the manual.
Why all that fuss around ORM, I did not want to create a new table, what I need is to access existing entities, remember? And I am not using Ant, who is using Ant nowadays? I am using Maven. So I had to understand how to create the sevice using maven and then where do I needed to put my classes in order to get my service up and running.
Build a service
In order to build a service, you can use a maven archetype.
mvn archetype:generate
then choose the option: com.liferay.maven.archetypes:liferay-servicebuilder-archetype (Provides an archetype to create Liferay Service Builder portlets.)
The Lifferay version: 2: 6.1.1
Define value for property 'groupId': : com.my.cms
Define value for property 'artifactId': : service
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': com.my.cms: :
The archetype then generate some code and modify the pom.xml of the current directory if any
directory:
pom.xml
service
├── pom.xml
├── service-portlet
│ ├── pom.xml
│ └── src
│ └── main
│ ├── resources
│ │ └── portlet.properties
│ └── webapp
│ ├── css
│ │ └── main.css
│ ├── icon.png
│ ├── js
│ │ └── main.js
│ ├── view.jsp
│ └── WEB-INF
│ ├── liferay-display.xml
│ ├── liferay-plugin-package.properties
│ ├── liferay-portlet.xml
│ ├── portlet.xml
│ ├── service.xml
│ └── web.xml
└── service-portlet-service
└── pom.xml The pom.xml on the parent directory is modified to add the “service” module. Be carreful to modify it if you already have a “modules” tag in order to add the “service” module in that tag.
<modules>
<module>service
</modules> As you can see, the Service Builder generated two portlets:
service-portlet
service-portlet-service
The service-portlet is a WAR containing the service to be deployed on you application server.
The service-portlet-service is a JAR containing the classes to be deployed in your portlet on the application server.
Implementation
service.xml
The first thing is to modify the service.xml file in order to have Service Builder to create all the stubs you need to register your service in liferay.
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<!-- service/service-portlet/src/main/webapp/WEB-INF/service.xml -->
<service-builder package-path="com.my.cms">
<namespace>service
<entity name="MyService" local-service="true" remote-service="true">
</entity>
</service-builder>
As you can see, I removed all the content of the entity tag, changed the name attribute to “MyService” instead of “Foo” and removed the uuid attribute.
Now, run service builder
cd service
mvn liferay:build-service
[INFO] Reactor Summary:
[INFO]
[INFO] service ........................................... SUCCESS [0.538s]
[INFO] service Portlet Service ........................... SUCCESS [0.299s]
[INFO] service Portlet ................................... SUCCESS [0.322s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
you can see the directory structure as some new files:
├── pom.xml
├── service-portlet
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ │ └── com
│ │ └── my
│ │ └── cms
│ │ └── service
│ │ ├── base
│ │ │ ├── MyServiceLocalServiceBaseImpl.java
│ │ │ ├── MyServiceLocalServiceClpInvoker.java
│ │ │ ├── MyServiceServiceBaseImpl.java
│ │ │ └── MyServiceServiceClpInvoker.java
│ │ ├── http
│ │ │ └── MyServiceServiceSoap.java
│ │ └── impl
│ │ ├── MyServiceLocalServiceImpl.java
│ │ └── MyServiceServiceImpl.java
│ ├── resources
│ │ ├── META-INF
│ │ │ ├── base-spring.xml
│ │ │ ├── cluster-spring.xml
│ │ │ ├── dynamic-data-source-spring.xml
│ │ │ ├── hibernate-spring.xml
│ │ │ ├── infrastructure-spring.xml
│ │ │ ├── portlet-hbm.xml
│ │ │ ├── portlet-model-hints.xml
│ │ │ ├── portlet-orm.xml
│ │ │ ├── portlet-spring.xml
│ │ │ └── shard-data-source-spring.xml
│ │ ├── portlet.properties
│ │ └── service.properties
│ └── webapp
│ ├── css
│ │ └── main.css
│ ├── icon.png
│ ├── js
│ │ ├── main.js
│ │ └── service.js
│ ├── view.jsp
│ └── WEB-INF
│ ├── liferay-display.xml
│ ├── liferay-plugin-package.properties
│ ├── liferay-portlet.xml
│ ├── portlet.xml
│ ├── service.xml
│ ├── service.xml~
│ ├── sql
│ │ ├── indexes.properties
│ │ ├── indexes.sql
│ │ ├── sequences.sql
│ │ └── tables.sql
│ └── web.xml
└── service-portlet-service
├── pom.xml
└── src
└── main
└── java
└── com
└── my
└── cms
└── service
├── ClpSerializer.java
├── messaging
│ └── ClpMessageListener.java
├── MyServiceLocalService.java
├── MyServiceLocalServiceClp.java
├── MyServiceLocalServiceUtil.java
├── MyServiceLocalServiceWrapper.java
├── MyServiceService.java
├── MyServiceServiceClp.java
├── MyServiceServiceUtil.java
└── MyServiceServiceWrapper.java
27 directories, 48 files
Now, everything is in place to add our custom sql. you can read about custom-sql in the manual
Custom-SQL
In order to use custom SQL you need to add a file containing your SQL queries, then to add a persistence class that will call execute that query. And call the method in a sevice util class.
SQL File
The file must be called custom-sql/default.xml and contain the SQL in a CDATA section:
<custom-sql>
<sql id="fr.meteo.cms.service.persistence.MeteoJournalArticleFinder.findLatestArticleByTagName">
<![CDATA[
SELECT ja.*
FROM mf3_liferay.journalarticle AS ja
JOIN (
SELECT SUBSTRING_INDEX(GROUP_CONCAT(uuid_ ORDER BY version DESC),',',1) AS uuid_LastVersion
FROM mf3_liferay.journalarticle ja
INNER JOIN mf3_liferay.assetentry ae
ON ja.resourcePrimKey = ae.classPK
INNER JOIN mf3_liferay.assetentries_assettags ae_at
ON ae.entryId = ae_at.entryId
INNER JOIN mf3_liferay.assettag tags
ON ae_at.tagId = tags.tagId
WHERE tags.name = ?
GROUP BY articleId
ORDER BY articleId DESC
) AS uuids
ON ja.uuid_ = uuids.uuid_LastVersion
]]>
</sql>
</custom-sql> Two points of attention here :
The file needs to be put in the portlet resource dir: service/service-portlet/src/main/resources/custom-sql/default.xml
The id attribute must contain the correct package name fr.meteo.cms.service.persistence.MeteoJournalArticleFinder + a unique name for the query: findLatestArticleByTagName
Persistence class
You need to add an implementation of the persistence class, the class that will implement the execution of the SQL query. The class need to be in that package: com.my.cms.service.persistence and in that path: service\service-portlet\src\main\java\com\my\cms\service\persistence\MyServiceFinderImpl.java
package com.my.cms.service.persistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import com.liferay.portlet.journal.model.JournalArticle;
public class MyServiceFinderImpl extends BasePersistenceImpl {
}
You need to pay attention to the name of the class, it must be MyServiceFinderImpl or liferay will not recognize it! and it must be in the right package.
When you have put the file in the persistence forlder in the portlet package, you need to run Service Builder again to get the stubs file generated.
mvn liferay:build-service
service
├── pom.xml
├── service.iml
├── service-portlet
│ ├── pom.xml
│ ├── service-portlet.iml
│ └── src
│ └── main
│ ├── java
│ │ └── com
│ │ └── my
│ │ └── cms
│ │ └── service
│ │ ├── base
│ │ │ ├── MyServiceLocalServiceBaseImpl.java
│ │ │ ├── MyServiceLocalServiceClpInvoker.java
│ │ │ ├── MyServiceServiceBaseImpl.java
│ │ │ └── MyServiceServiceClpInvoker.java
│ │ ├── http
│ │ │ └── MyServiceServiceSoap.java
│ │ ├── impl
│ │ │ ├── MyServiceLocalServiceImpl.java
│ │ │ └── MyServiceServiceImpl.java
│ │ └── persistence
│ │ └── MyServiceFinderImpl.java
│ ├── resources
│ │ ├── custom-sql
│ │ │ └── default.xml
│ │ ├── META-INF
│ │ │ ├── base-spring.xml
│ │ │ ├── cluster-spring.xml
│ │ │ ├── dynamic-data-source-spring.xml
│ │ │ ├── hibernate-spring.xml
│ │ │ ├── infrastructure-spring.xml
│ │ │ ├── portlet-hbm.xml
│ │ │ ├── portlet-model-hints.xml
│ │ │ ├── portlet-orm.xml
│ │ │ ├── portlet-spring.xml
│ │ │ └── shard-data-source-spring.xml
│ │ ├── portlet.properties
│ │ └── service.properties
│ └── webapp
│ ├── css
│ │ └── main.css
│ ├── icon.png
│ ├── js
│ │ ├── main.js
│ │ └── service.js
│ ├── view.jsp
│ └── WEB-INF
│ ├── liferay-display.xml
│ ├── liferay-plugin-package.properties
│ ├── liferay-portlet.xml
│ ├── portlet.xml
│ ├── service.xml
│ ├── service.xml~
│ ├── sql
│ │ ├── indexes.properties
│ │ ├── indexes.sql
│ │ ├── sequences.sql
│ │ └── tables.sql
│ └── web.xml
└── service-portlet-service
├── pom.xml
├── service-portlet-service.iml
└── src
└── main
└── java
└── com
└── my
└── cms
└── service
├── ClpSerializer.java
├── messaging
│ └── ClpMessageListener.java
├── MyServiceLocalService.java
├── MyServiceLocalServiceClp.java
├── MyServiceLocalServiceUtil.java
├── MyServiceLocalServiceWrapper.java
├── MyServiceService.java
├── MyServiceServiceClp.java
├── MyServiceServiceUtil.java
├── MyServiceServiceWrapper.java
└── persistence
├── MyServiceFinder.java
└── MyServiceFinderUtil.java
30 directories, 55 files liferay added or modified those files:
service/service-portlet/src/main/webapp/WEB-INF/sql/tables.sql
service/service-portlet/src/main/resources/service.properties
service/service-portlet/src/main/java/com/my/cms/service/base/MyServiceLocalServiceClpInvoker.java
service/service-portlet/src/main/java/com/my/cms/service/base/MyServiceServiceBaseImpl.java
service/service-portlet/src/main/java/com/my/cms/service/base/MyServiceServiceClpInvoker.java
service/service-portlet/src/main/resources/META-INF/portlet-spring.xml
service/service-portlet/src/main/java/com/my/cms/service/base/MyServiceLocalServiceBaseImpl.java
service/service-portlet-service/src/main/java/com/my/cms/service/persistence/MyServiceFinder.java
service/service-portlet-service/src/main/java/com/my/cms/service/persistence/MyServiceFinderUtil.java
You can now implements the method findLatestArticleByTagName in the MyServiceFinderImpl file
package com.my.cms.service.persistence;
import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
import com.liferay.portal.kernel.dao.orm.*;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import com.liferay.portlet.journal.model.JournalArticle;
import com.liferay.util.dao.orm.CustomSQLUtil;
import java.util.List;
public class MyServiceFinderImpl extends BasePersistenceImpl implements MyServiceFinder {
public List findLatestArticleByTagName(
String tagName,
int begin, int end) {
Session session = null;
try {
SessionFactory sessionFactory = (SessionFactory) PortalBeanLocatorUtil.locate("liferaySessionFactory");
session = sessionFactory.openSession();
String sql = CustomSQLUtil.get(
FIND_BY_LATEST_ARTICLES_BY_TAGNAME);
SQLQuery q = session.createSQLQuery(sql);
q.setCacheable(false);
q.addEntity("JournalArticle_JournalArticle", PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portlet.journal.model.impl.JournalArticleImpl"));
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(tagName);
return (List) QueryUtil.list(q, getDialect(), begin, end);
} catch (Exception e) {
try {
throw new SystemException(e);
} catch (SystemException se) {
se.printStackTrace();
}
} finally {
closeSession(session);
}
return null;
}
public static final String FIND_BY_LATEST_ARTICLES_BY_TAGNAME =
MyServiceFinder.class.getName() +
".findLatestArticleByTagName";
}
I you want to use an existing session and connect your service to it, you can use that line of code:
SessionFactory sessionFactory = (SessionFactory) PortalBeanLocatorUtil.locate("liferaySessionFactory"); You can find the entity you are looking for by using the class loader:
PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portlet.journal.model.impl.JournalArticleImpl") Then launch again the Service Builder in order to propagate the findLatestArticleByTagName method
mvn liferay:build-service You need now to add the method in the com.my.cms.service.impl.MyServiceLocalServiceImpl class in order to use it.
public List findLatestArticleByTagName(
String tagName,
int begin, int end) {
return MyServiceFinderUtil.findLatestArticleByTagName(tagName, begin, end);
}
Then launch again the Service Builder in order to propagate the findLatestArticleByTagName method in different classes.
mvn liferay:build-service
Use the service in a portlet
In order to use the service in the portlet, you need to do some configuration first.
Add the dependency to the Service’s portlet in liferay(service/service-portlet/src/main/webapp/WEB-INF/liferay-plugin-package.properties), this will ensure that the portlet using the service will not be deployed before the service:
required-deployment-contexts=service-portlet
Add the dependency to the Service’s portlet in maven in order to get the JAR file:
<dependency>
<groupId>com.my.cms</groupId>
<artifactId>service-portlet-service</artifactId>
<version>${pom.version}</version>
</dependency> Rebuild and redeploy the service in liferay application server.
You can test your service in your portlet using the Util class:
List journalArticles = MyServiceLocalServiceUtil.findLatestArticleByTagName("actualités de recherche", currentPage, currentPage + 8);

MATLAB: Using genpath with partial paths

I have the following directory structure:
├── root
│ ├── DATA
│ │ ├── GLOBAL
│ ├── project1
│ │ ├── branches
│ │ │ └── dev
│ │ │ └── project.m
│ │ └── trunk
│ │ └── project.m
How would I elegantly go about adding DATA/GLOBAL to the path from both project.m files?
Essentially, I'm looking to make genpath work for partial paths. exist('DATA/GLOBAL') returns 7 (a directory was found), but genpath('DATA/GLOBAL') returns '' (no path generated).
Using regex to look for the part in pwd that all project.m should have in common is a fairly robust way:
P = regexp(pwd, ['^.*root' filesep], 'match');
if isempty(P)
error('project:globaldir_missing',...
'Could not find global data directory.');
end
newPath = [P{1} 'DATA' filesep 'GLOBAL'];
if ~exist(newPath , 'dir')
error('project:pathing_error',...
'Global data directory does not seem to exist.');
end
genpath(newPath);
By using filesep you make it independent of OS specifics, e.g., this will work on any OS.
Note that you create a dependency on the specific directory tree of your project, but well, such is the MATLAB way.