Skip to content

Instantly share code, notes, and snippets.

View evaldeslacasa's full-sized avatar

Enrique Valdes Lacasa evaldeslacasa

  • Thirdwave LLC
  • Madrid
View GitHub Profile
@evaldeslacasa
evaldeslacasa / gist:dfa8ce6615779ad5313aa88b852df4e9
Last active September 4, 2019 11:21
Pagination for dynamic Asset Publisher using ADT (hard-coded delta though)
#set ($AssetEntryLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService"))
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
#set( $structureId = $journalArticle.getStructureId() )
#set ($ddmStructureLocalService = $serviceLocator.findService("com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalService") )
#set( $numNews = $journalArticleLocalService.getStructureArticles($groupId, $structureId) )
#set( $newsUrl = $layout.getFriendlyURL() )
#set( $newsArticles = $journalArticleLocalService.getStructureArticles($groupId, $structureId) )
#set( $checkedArticleIds = [] )
#set( $newsArticles = $journalArticleLocalService.getStructureArticles($groupId, $structureId) )
#set( $checkedArticleIds = [] )
#foreach ($newArticle in $newsArticles)
#set ( $articleId = $newArticle.getArticleId() )
#set ( $articleIdStr = $getterUtil.getString($articleId))
#set ( $firstChar = $articleIdStr.substring(0,1).toLowerCase())
#set ( $slash = "/")
#if((!$checkedArticleIds.contains($articleId))&&($firstChar != $slash) )
@evaldeslacasa
evaldeslacasa / gist:55d27fb064965bdee2c8d0642b2c80bf
Created May 4, 2016 17:38
Error when spending too much time debugging
19:37:18,748 ERROR [http-bio-8080-exec-36][JDBCExceptionReporter:82] Connection has already been closed.
19:37:18,756 INFO [http-bio-8080-exec-36][CustomerFinderImpl:377] org.hibernate.exception.GenericJDBCException: could not execute query
@evaldeslacasa
evaldeslacasa / gist:3cb37d4fb9afd636700d10261d73d8d8
Created April 1, 2016 17:52
Code to add unique long values to HashSet
String[] ids = StringUtil.split(idStr, StringPool.COMMA);
Set<String> idSet = new HashSet<String>();
for (int i = 0; i < ids.length; i++) {
if(!idSet.contains(ids[i])){
idSet.add(ids[i]);
}
}
@evaldeslacasa
evaldeslacasa / gist:d85110fee9fd93ea2a11
Last active February 1, 2016 16:29
Method to download file from URL in Java when the URL is redirected - statusCode = 301 resource temp moved
public static final File downloadColorImage(String colorUrlString){
File file = new File(System.getProperty( "catalina.base" ) + "/colorFile.png");
try {
URL colorUrl = new URL(colorUrlString);
HttpURLConnection huc = (HttpURLConnection)colorUrl.openConnection();
int statusCode = huc.getResponseCode(); //get response code
if (statusCode == HttpURLConnection.HTTP_MOVED_TEMP
|| statusCode == HttpURLConnection.HTTP_MOVED_PERM){ // if file is moved, then pick new URL
@evaldeslacasa
evaldeslacasa / gist:12318e446aaa0de0a8b8
Created December 15, 2015 20:39
HTTP POST request to API for retrieving OAuth token
String userName = API_CLIENT_ID;
String password = API_CLIENT_SECRET;
String tokenApiUrl = OAUTH_API_URL;
byte[] encodedBytes = Base64.encodeBase64((userName+":"+password).getBytes());
String encoding = new String(encodedBytes);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost();
URI uri = new URI(tokenApiUrl);
@evaldeslacasa
evaldeslacasa / gist:c19cfef283fd6de922a9
Last active November 23, 2015 23:19
aui script to use in button
the main.js:
AUI().ready(
/*
This function gets loaded when all the HTML, not including the portlets, is
loaded.
*/
function() {
alert("hola");
@evaldeslacasa
evaldeslacasa / gist:5893654365449bd5f10c
Created November 11, 2015 00:45
Data too long for "value" of "urlKey" in category
00:35:09,747 ERROR [http-bio-8080-exec-71][JDBCExceptionReporter:82] Data truncation: Data too long for column 'value' at row 1
00:35:09,748 ERROR [http-bio-8080-exec-71][DefaultTransactionExecutor:93] Application exception overridden by commit exception
org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into AssetCategoryProperty (companyId, userId, userName, createDate, modifiedDate, categoryId, key_, value, categoryPropertyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.DataException: Could not execute JDBC batch update
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:642)
at org.springframework.orm.hibernate3.SpringSessionSynchronization.translateException(SpringSessionSynchronization.java:160)
at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:148)
at org.springframework.transaction.
@evaldeslacasa
evaldeslacasa / dynamicPageTemplate.java
Last active November 3, 2015 23:29
Dynamic Query to get Products page template
ClassLoader classLoader = PortalClassLoaderUtil.getClassLoader();
DynamicQuery templateQuery = DynamicQueryFactoryUtil.forClass(LayoutPrototype.class,classLoader)
.add(PropertyFactoryUtil.forName("name").like("%>Product<%"));
List<LayoutPrototype> templates = LayoutPrototypeLocalServiceUtil.dynamicQuery(templateQuery);
LayoutPrototype productsPageTemplate = templates.get(0);
@evaldeslacasa
evaldeslacasa / portal-session-ext.properties
Last active September 23, 2015 22:03
Recommended session extension timeout - Liferay
#
# Specify the number of minutes before a session expires. This value is
# always overridden by the value set in web.xml. NOTE: the <session-timeout>
# attribute in the web.xml files overrides these values. Comment them out.
#
session.timeout=5
#
# Set the auto-extend mode to true to avoid having to ask the user whether
# to extend the session or not. Instead, it will be automatically extended.