List of usage examples for com.liferay.portal.kernel.util DateFormatFactoryUtil getSimpleDateFormat
public static DateFormat getSimpleDateFormat(String pattern)
From source file:com.liferay.asset.publisher.upgrade.v1_0_0.test.UpgradePortletPreferencesTest.java
License:Open Source License
protected void setUpDateFormatFactories() { _newDateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyy-MM-dd"); _oldDateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmmss"); }
From source file:com.liferay.asset.publisher.web.portlet.AssetPublisherPortlet.java
License:Open Source License
public void getFieldValue(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); try {//from ww w. j a va 2 s .c o m ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest); long structureId = ParamUtil.getLong(resourceRequest, "structureId"); Fields fields = (Fields) serviceContext.getAttribute(Fields.class.getName() + structureId); if (fields == null) { String fieldsNamespace = ParamUtil.getString(resourceRequest, "fieldsNamespace"); fields = DDMUtil.getFields(structureId, fieldsNamespace, serviceContext); } String fieldName = ParamUtil.getString(resourceRequest, "name"); Field field = fields.get(fieldName); Serializable fieldValue = field.getValue(themeDisplay.getLocale(), 0); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (fieldValue != null) { jsonObject.put("success", true); } else { jsonObject.put("success", false); writeJSON(resourceRequest, resourceResponse, jsonObject); return; } DDMStructure ddmStructure = field.getDDMStructure(); String type = ddmStructure.getFieldType(fieldName); Serializable displayValue = DDMUtil.getDisplayFieldValue(themeDisplay, fieldValue, type); jsonObject.put("displayValue", String.valueOf(displayValue)); if (fieldValue instanceof Boolean) { jsonObject.put("value", (Boolean) fieldValue); } else if (fieldValue instanceof Date) { DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMM ddHHmmss"); jsonObject.put("value", dateFormat.format(fieldValue)); } else if (fieldValue instanceof Double) { jsonObject.put("value", (Double) fieldValue); } else if (fieldValue instanceof Float) { jsonObject.put("value", (Float) fieldValue); } else if (fieldValue instanceof Integer) { jsonObject.put("value", (Integer) fieldValue); } else if (fieldValue instanceof Number) { jsonObject.put("value", String.valueOf(fieldValue)); } else { jsonObject.put("value", (String) fieldValue); } writeJSON(resourceRequest, resourceResponse, jsonObject); } catch (Exception e) { throw new PortletException(e); } }
From source file:com.liferay.asset.publisher.web.upgrade.v1_0_0.UpgradePortletPreferences.java
License:Open Source License
public UpgradePortletPreferences(DDMStructureLocalService ddmStructureLocalService, DDMStructureLinkLocalService ddmStructureLinkLocalService, SAXReader saxReader) { _ddmStructureLocalService = ddmStructureLocalService; _ddmStructureLinkLocalService = ddmStructureLinkLocalService; _saxReader = saxReader;// w ww . j ava 2s . co m _newDateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyy-MM-dd"); _oldDateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmmss"); }
From source file:com.liferay.asset.test.util.BaseAssetSearchTestCase.java
License:Open Source License
protected void testOrderByExpirationDate(final AssetEntryQuery assetEntryQuery, final String orderByType, final Date[] expirationDates) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group1.getGroupId()); BaseModel<?> parentBaseModel = getParentBaseModel(_group1, serviceContext); final SearchContext searchContext = SearchContextTestUtil.getSearchContext(); searchContext.setGroupIds(assetEntryQuery.getGroupIds()); for (Date expirationDate : expirationDates) { addBaseModel(parentBaseModel, RandomTestUtil.randomString(), expirationDate, serviceContext); }//ww w .jav a 2s .co m assetEntryQuery.setOrderByCol1("expirationDate"); assetEntryQuery.setOrderByType1(orderByType); Arrays.sort(expirationDates); final DateFormat dateFormat = DateFormatFactoryUtil .getSimpleDateFormat(PropsValues.INDEX_DATE_FORMAT_PATTERN); List<AssetEntry> assetEntries = search(assetEntryQuery, searchContext); Assert.assertEquals(ArrayUtils.toString(format(expirationDates, dateFormat)), ArrayUtils.toString(format(getExpirationDates(assetEntries, orderByType), dateFormat))); }
From source file:com.liferay.calendar.search.test.CalendarBookingIndexerIndexedFieldsTest.java
License:Open Source License
@Test public void testIndexedFields() throws Exception { String originalTitle = "entity title"; String translatedTitle = "entitas neve"; String description = StringUtil.toLowerCase(RandomTestUtil.randomString()); CalendarBooking calendarBooking = addCalendarBooking(new LocalizedValuesMap() { {/*from w ww. ja v a 2 s . c om*/ put(LocaleUtil.US, originalTitle); put(LocaleUtil.HUNGARY, translatedTitle); } }, new LocalizedValuesMap() { { put(LocaleUtil.US, originalTitle); put(LocaleUtil.HUNGARY, translatedTitle); } }, new LocalizedValuesMap() { { put(LocaleUtil.US, description); put(LocaleUtil.HUNGARY, description); } }); Map<String, String> map = new HashMap<>(); map.put(Field.CLASS_NAME_ID, String.valueOf(portal.getClassNameId(Calendar.class))); map.put(Field.EXPIRATION_DATE, "99950812133000"); map.put(Field.EXPIRATION_DATE.concat("_sortable"), "9223372036854775807"); map.put(Field.PRIORITY, "0.0"); map.put(Field.PUBLISH_DATE, "19700101000000"); map.put(Field.PUBLISH_DATE.concat("_sortable"), "0"); map.put(Field.RELATED_ENTRY, "true"); map.put(Field.STAGING_GROUP, "false"); map.put(Field.STATUS, "0"); map.put("viewActionId", CalendarActionKeys.VIEW_BOOKING_DETAILS); populateTitle(originalTitle, map); populateTranslatedTitle(translatedTitle, map); CalendarResource calendarResource = calendarBooking.getCalendarResource(); populateCalendarResource(calendarResource, map); Calendar calendar = calendarResource.getDefaultCalendar(); populateCalendar(calendar, map); populateCalendarBooking(calendarBooking, map); DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmm"); populateCalendarDate(Field.CREATE_DATE, calendar.getCreateDate(), dateFormat, map); populateCalendarDate(Field.MODIFIED_DATE, calendar.getModifiedDate(), dateFormat, map); calendarFieldsFixture.populateGroupRoleId(map); calendarFieldsFixture.populateRoleId("Owner", map); calendarFieldsFixture.populateUID(calendarBooking, map); String keywords = "nev"; Document document = calendarSearchFixture.searchOnlyOne(keywords, LocaleUtil.HUNGARY); adjustDatePrecision(Field.CREATE_DATE, document, dateFormat); adjustDatePrecision(Field.MODIFIED_DATE, document, dateFormat); FieldValuesAssert.assertFieldValues(map, document, keywords); }
From source file:com.liferay.calendar.search.test.CalendarIndexerIndexedFieldsTest.java
License:Open Source License
protected void populateExpectedFieldValues(Calendar calendar, Map<String, String> map) throws Exception { map.put(Field.COMPANY_ID, String.valueOf(calendar.getCompanyId())); map.put(Field.DEFAULT_LANGUAGE_ID, calendar.getDefaultLanguageId()); map.put(Field.ENTRY_CLASS_NAME, calendar.getModelClassName()); map.put(Field.ENTRY_CLASS_PK, String.valueOf(calendar.getCalendarId())); map.put(Field.GROUP_ID, String.valueOf(calendar.getGroupId())); map.put(Field.SCOPE_GROUP_ID, String.valueOf(calendar.getGroupId())); map.put(Field.STAGING_GROUP, "false"); map.put(Field.USER_ID, String.valueOf(calendar.getUserId())); map.put(Field.USER_NAME, StringUtil.toLowerCase(calendar.getUserName())); map.put("calendarId", String.valueOf(calendar.getCalendarId())); DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmmss"); populateCalendarDate(Field.CREATE_DATE, calendar.getCreateDate(), map, dateFormat); populateCalendarDate(Field.MODIFIED_DATE, calendar.getModifiedDate(), map, dateFormat); populateCalendarResource(calendar.getCalendarResource(), calendar, map); calendarFieldsFixture.populateGroupRoleId(map); calendarFieldsFixture.populateRoleId("Guest", map); calendarFieldsFixture.populateUID(calendar, map); }
From source file:com.liferay.document.library.repository.cmis.search.CMISParameterValueUtil.java
License:Open Source License
public static String formatParameterValue(String field, String value, boolean wildcard, QueryConfig queryConfig) {/* w w w. j av a 2s . c o m*/ if (field.equals(Field.CREATE_DATE) || field.equals(Field.MODIFIED_DATE)) { try { DateFormat searchSimpleDateFormat = DateFormatFactoryUtil .getSimpleDateFormat(_INDEX_DATE_FORMAT_PATTERN); Date date = searchSimpleDateFormat.parse(value); DateFormat cmisSimpleDateFormat = DateFormatFactoryUtil .getSimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.000'Z'"); value = cmisSimpleDateFormat.format(date); } catch (ParseException pe) { if (_log.isWarnEnabled()) { _log.warn("Unable to parse date " + value + " for field " + field); } } } else { String productName = StringPool.BLANK; if (queryConfig != null) { productName = (String) queryConfig.getAttribute("repositoryProductName"); } if (Validator.isNotNull(productName) && productName.startsWith("Alfresco")) { value = StringUtil.replace(value, CharPool.APOSTROPHE, "\\'"); } else { value = StringUtil.replace(value, new char[] { CharPool.APOSTROPHE, CharPool.UNDERLINE }, new String[] { "\\'", "\\_" }); } if (wildcard) { value = StringUtil.replace(value, new char[] { CharPool.PERCENT, CharPool.STAR }, new String[] { "\\%", StringPool.PERCENT }); } } return value; }
From source file:com.liferay.document.library.repository.external.ExtRepositoryQueryMapperImpl.java
License:Open Source License
@Override public Date formatDateParameterValue(String fieldName, String fieldValue) throws SearchException { if (fieldName.equals(Field.CREATE_DATE) || fieldName.equals(Field.MODIFIED_DATE)) { try {/*from w w w . j a v a2 s . c o m*/ DateFormat searchSimpleDateFormat = DateFormatFactoryUtil .getSimpleDateFormat(_INDEX_DATE_FORMAT_PATTERN); return searchSimpleDateFormat.parse(fieldValue); } catch (ParseException pe) { throw new SearchException("Unable to parse date " + fieldValue + " for field " + fieldName); } } else { throw new SearchException("Field " + fieldName + " is not a date"); } }
From source file:com.liferay.dynamic.data.mapping.internal.util.DDMImpl.java
License:Open Source License
@Override public Serializable getIndexedFieldValue(Serializable fieldValue, String type) throws Exception { if (fieldValue instanceof Date) { Date valueDate = (Date) fieldValue; DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmmss"); fieldValue = dateFormat.format(valueDate); } else if (type.equals(DDMImpl.TYPE_SELECT)) { String valueString = (String) fieldValue; JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString); String[] stringArray = ArrayUtil.toStringArray(jsonArray); fieldValue = stringArray[0];//from w ww . j av a 2 s . co m } return fieldValue; }
From source file:com.liferay.journal.exportimport.data.handler.test.ManifestSummaryTest.java
License:Open Source License
@Override protected void validateExport(PortletDataContext portletDataContext, StagedModel stagedModel, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception { ManifestSummary manifestSummary = portletDataContext.getManifestSummary(); Map<String, LongWrapper> modelAdditionCounters = manifestSummary.getModelAdditionCounters(); Assert.assertEquals(modelAdditionCounters.toString(), 4, modelAdditionCounters.size()); Assert.assertEquals(1, manifestSummary .getModelAdditionCount(new StagedModelType(DDMStructure.class, JournalArticle.class))); Assert.assertEquals(1,/*w w w .ja v a 2 s. c o m*/ manifestSummary.getModelAdditionCount(new StagedModelType(DDMTemplate.class, DDMStructure.class))); Assert.assertEquals(1, manifestSummary.getModelAdditionCount(new StagedModelType(JournalArticle.class))); Assert.assertEquals(1, manifestSummary.getModelAdditionCount(new StagedModelType(JournalFolder.class))); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); Element headerElement = rootElement.addElement("header"); DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat(Time.RFC822_FORMAT); String rfc822DateString = Time.getRFC822(); _exportDate = dateFormat.parse(rfc822DateString); headerElement.addAttribute("export-date", rfc822DateString); ExportImportHelperUtil.writeManifestSummary(document, manifestSummary); zipWriter.addEntry("/manifest.xml", document.asXML()); }