org.alfresco.service.cmr.repository.Period Java Examples
The following examples show how to use
org.alfresco.service.cmr.repository.Period.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PeriodTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * "none" */ public void test01NoPeriod() { assertTrue(Period.getProviderNames().contains(NoPeriod.PERIOD_TYPE)); Period period = new Period(NoPeriod.PERIOD_TYPE); assertNull(period.getNextDate(new Date())); PeriodProvider provider = Period.getProvider(NoPeriod.PERIOD_TYPE); assertNull(provider.getDefaultExpression()); assertEquals(provider.getExpressionMutiplicity(), PeriodProvider.ExpressionMutiplicity.NONE); assertNull(provider.getNextDate(new Date(), null)); assertNull(provider.getNextDate(new Date(), "")); assertNull(provider.getNextDate(new Date(), "meep")); assertEquals(provider.getPeriodType(), NoPeriod.PERIOD_TYPE); assertNull(provider.getExpressionDataType()); assertEquals("None", provider.getDisplayLabel()); }
Example #2
Source File: PropertyFieldProcessor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private PeriodDataTypeParameters getPeriodOptions() { PeriodDataTypeParameters periodOptions = new PeriodDataTypeParameters(); Set<String> providers = Period.getProviderNames(); for (String provider : providers) { periodOptions.addPeriodProvider(Period.getProvider(provider)); } return periodOptions; }
Example #3
Source File: PeriodTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Test a missing expression, ensure 1 is used as the default */ public void test18MissingExpression() { assertTrue(Period.getProviderNames().contains(Days.PERIOD_TYPE)); Date now = new Date(); Calendar calendar = Calendar.getInstance(); Period period = new Period(Days.PERIOD_TYPE + "|"); assertNotNull(period.getNextDate(now)); calendar.setTime(now); calendar.add(Calendar.DAY_OF_YEAR, 1); assertEquals(period.getNextDate(now), calendar.getTime()); }
Example #4
Source File: AbstractPeriodProvider.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void afterPropertiesSet() throws Exception { Period.registerProvider(this); }
Example #5
Source File: NodePropertyValue.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override Serializable convert(Serializable value) { return DefaultTypeConverter.INSTANCE.convert(Period.class, value); }
Example #6
Source File: NodePropertyValue.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Determine the actual value type to aid in more concise persistence. * * @param value the value that is to be persisted * @return Returns the value type equivalent of the */ private static ValueType getActualType(Serializable value) { if (value == null) { return ValueType.NULL; } else if (value instanceof Boolean) { return ValueType.BOOLEAN; } else if (value instanceof Integer) { return ValueType.INTEGER; } else if (value instanceof Long) { return ValueType.LONG; } else if (value instanceof Float) { return ValueType.FLOAT; } else if (value instanceof Double) { return ValueType.DOUBLE; } else if (value instanceof String) { return ValueType.STRING; } else if (value instanceof Date) { return ValueType.DATE; } else if (value instanceof NodeRef) { return ValueType.NODEREF; } else if (value instanceof ChildAssociationRef) { return ValueType.CHILD_ASSOC_REF; } else if (value instanceof AssociationRef) { return ValueType.ASSOC_REF; } else if (value instanceof QName) { return ValueType.QNAME; } else if (value instanceof Path) { return ValueType.PATH; } else if (value instanceof Locale) { return ValueType.LOCALE; } else if (value instanceof VersionNumber) { return ValueType.VERSION_NUMBER; } else if (value instanceof Period) { return ValueType.PERIOD; } else if (value instanceof ContentDataId) { return ValueType.CONTENT_DATA_ID; } else if (value instanceof ContentDataWithId) { return ValueType.CONTENT_DATA_ID; } else if (value instanceof ContentData) { return ValueType.CONTENT; } else if (value instanceof SealedObject) { return ValueType.SEALED_OBJECT; } else { // type is not recognised as belonging to any particular slot return ValueType.SERIALIZABLE; } }
Example #7
Source File: PeriodTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * End of FQ * * @throws ParseException */ public void test12EndOfDefaultFinancialQuarter() throws ParseException { PeriodProvider provider = Period.getProvider(EndOfFinancialQuarter.PERIOD_TYPE); assertEquals(provider.getDefaultExpression(), "1"); assertEquals(provider.getExpressionMutiplicity(), PeriodProvider.ExpressionMutiplicity.OPTIONAL); assertEquals(provider.getPeriodType(), EndOfFinancialQuarter.PERIOD_TYPE); assertEquals(DataTypeDefinition.INT, provider.getExpressionDataType()); assertEquals("End Of Financial Quarter", provider.getDisplayLabel()); AbstractEndOfCalendarPeriodProvider instance = (AbstractEndOfCalendarPeriodProvider) provider; instance.setStartDayOfMonth(1); instance.setStartMonth(Calendar.JANUARY); SimpleDateFormat df = CachingDateFormat.getDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", true); Period period = new Period(EndOfFinancialQuarter.PERIOD_TYPE); Date date; date = df.parse("2008-10-01T00:00:00.000"); assertEquals("2008-12-31T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2008-12-31T23:59:59.998"); assertEquals("2008-12-31T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2008-12-31T23:59:59.999"); assertEquals("2009-03-31T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-01-01T00:00:00.000"); assertEquals("2009-03-31T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-03-31T23:59:59.998"); assertEquals("2009-03-31T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-03-31T23:59:59.999"); assertEquals("2009-06-30T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-04-01T00:00:00.000"); assertEquals("2009-06-30T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-06-30T23:59:59.998"); assertEquals("2009-06-30T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-06-30T23:59:59.999"); assertEquals("2009-09-30T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-07-01T00:00:00.000"); assertEquals("2009-09-30T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-09-30T23:59:59.998"); assertEquals("2009-09-30T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-09-30T23:59:59.999"); assertEquals("2009-12-31T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-10-01T00:00:00.000"); assertEquals("2009-12-31T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-12-31T23:59:59.998"); assertEquals("2009-12-31T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-12-31T23:59:59.999"); assertEquals("2010-03-31T23:59:59.999", df.format(period.getNextDate(date))); }
Example #8
Source File: PeriodTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * End of FQ * * @throws ParseException */ public void test14EndOfUKTaxQuarter() throws ParseException { PeriodProvider provider = Period.getProvider(EndOfFinancialQuarter.PERIOD_TYPE); assertEquals(provider.getDefaultExpression(), "1"); assertEquals(provider.getExpressionMutiplicity(), PeriodProvider.ExpressionMutiplicity.OPTIONAL); assertEquals(provider.getPeriodType(), EndOfFinancialQuarter.PERIOD_TYPE); assertEquals(DataTypeDefinition.INT, provider.getExpressionDataType()); AbstractEndOfCalendarPeriodProvider instance = (AbstractEndOfCalendarPeriodProvider) provider; instance.setStartDayOfMonth(6); instance.setStartMonth(Calendar.APRIL); SimpleDateFormat df = CachingDateFormat.getDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", true); Period period = new Period(EndOfFinancialQuarter.PERIOD_TYPE); Date date; date = df.parse("2008-04-06T00:00:00.000"); assertEquals("2008-07-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2008-07-05T23:59:59.998"); assertEquals("2008-07-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2008-07-05T23:59:59.999"); assertEquals("2008-10-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2008-07-06T00:00:00.000"); assertEquals("2008-10-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2008-10-05T23:59:59.998"); assertEquals("2008-10-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2008-10-05T23:59:59.999"); assertEquals("2009-01-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2008-10-06T00:00:00.000"); assertEquals("2009-01-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-01-05T23:59:59.998"); assertEquals("2009-01-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-01-05T23:59:59.999"); assertEquals("2009-04-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-01-06T00:00:00.000"); assertEquals("2009-04-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-04-05T23:59:59.998"); assertEquals("2009-04-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-04-05T23:59:59.999"); assertEquals("2009-07-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-04-06T00:00:00.000"); assertEquals("2009-07-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-07-05T23:59:59.998"); assertEquals("2009-07-05T23:59:59.999", df.format(period.getNextDate(date))); date = df.parse("2009-07-05T23:59:59.999"); assertEquals("2009-10-05T23:59:59.999", df.format(period.getNextDate(date))); }
Example #9
Source File: DefaultTypeConverterTest.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public void testToString() { assertEquals("true", DefaultTypeConverter.INSTANCE.convert(String.class, new Boolean(true))); assertEquals("false", DefaultTypeConverter.INSTANCE.convert(String.class, new Boolean(false))); assertEquals("v", DefaultTypeConverter.INSTANCE.convert(String.class, Character.valueOf('v'))); assertEquals("3", DefaultTypeConverter.INSTANCE.convert(String.class, Byte.valueOf("3"))); assertEquals("4", DefaultTypeConverter.INSTANCE.convert(String.class, Short.valueOf("4"))); assertEquals("5", DefaultTypeConverter.INSTANCE.convert(String.class, Integer.valueOf("5"))); assertEquals("6", DefaultTypeConverter.INSTANCE.convert(String.class, Long.valueOf("6"))); assertEquals("7.1", DefaultTypeConverter.INSTANCE.convert(String.class, Float.valueOf("7.1"))); assertEquals("NaN", DefaultTypeConverter.INSTANCE.convert(String.class, Float.NaN)); assertEquals("-Infinity", DefaultTypeConverter.INSTANCE.convert(String.class, Float.NEGATIVE_INFINITY)); assertEquals("Infinity", DefaultTypeConverter.INSTANCE.convert(String.class, Float.POSITIVE_INFINITY)); assertEquals("123.123", DefaultTypeConverter.INSTANCE.convert(String.class, Double.valueOf("123.123"))); assertEquals("NaN", DefaultTypeConverter.INSTANCE.convert(String.class, Double.NaN)); assertEquals("-Infinity", DefaultTypeConverter.INSTANCE.convert(String.class, Double.NEGATIVE_INFINITY)); assertEquals("Infinity", DefaultTypeConverter.INSTANCE.convert(String.class, Double.POSITIVE_INFINITY)); assertEquals("1234567890123456789", DefaultTypeConverter.INSTANCE.convert(String.class, new BigInteger("1234567890123456789"))); assertEquals("12345678901234567890.12345678901234567890", DefaultTypeConverter.INSTANCE.convert(String.class, new BigDecimal("12345678901234567890.12345678901234567890"))); Date date = new Date(); assertEquals(ISO8601DateFormat.format(date), DefaultTypeConverter.INSTANCE.convert(String.class, date)); assertEquals("P0Y25D", DefaultTypeConverter.INSTANCE.convert(String.class, new Duration("P0Y25D"))); assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String.class, "woof")); // MLText MLText mlText = new MLText("woof"); mlText.addValue(Locale.SIMPLIFIED_CHINESE, "缂"); assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String.class, mlText)); // Locale assertEquals("fr_FR_", DefaultTypeConverter.INSTANCE.convert(String.class, Locale.FRANCE)); // VersionNumber assertEquals("1.2.3", DefaultTypeConverter.INSTANCE.convert(String.class, new VersionNumber("1.2.3"))); // Period assertEquals("period", DefaultTypeConverter.INSTANCE.convert(String.class, new Period("period"))); assertEquals("period|12", DefaultTypeConverter.INSTANCE.convert(String.class, new Period("period|12"))); Map<String,String> periodMap = new HashMap<>(); periodMap.put("periodType","month"); periodMap.put("expression","1"); assertEquals(new Period("month|1"), DefaultTypeConverter.INSTANCE.convert(Period.class, new Period(periodMap))); // Java Class assertEquals(this.getClass(), DefaultTypeConverter.INSTANCE.convert(Class.class, this.getClass().getName())); }
Example #10
Source File: DefaultTypeConverterTest.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public void testFromString() { assertEquals(Boolean.valueOf(true), DefaultTypeConverter.INSTANCE.convert(Boolean.class, "True")); assertEquals(Boolean.valueOf(false), DefaultTypeConverter.INSTANCE.convert(Boolean.class, "woof")); assertEquals(Character.valueOf('w'), DefaultTypeConverter.INSTANCE.convert(Character.class, "w")); assertEquals(Byte.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Byte.class, "3")); assertEquals(Short.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Short.class, "4")); assertEquals(Integer.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Integer.class, "5")); assertEquals(Long.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Long.class, "6")); assertEquals(Float.valueOf("7.1"), DefaultTypeConverter.INSTANCE.convert(Float.class, "7.1")); assertEquals(Float.NaN, DefaultTypeConverter.INSTANCE.convert(Float.class, "NaN")); assertEquals(Float.NEGATIVE_INFINITY, DefaultTypeConverter.INSTANCE.convert(Float.class, "-Infinity")); assertEquals(Float.POSITIVE_INFINITY, DefaultTypeConverter.INSTANCE.convert(Float.class, "Infinity")); assertEquals(Double.valueOf("123.123"), DefaultTypeConverter.INSTANCE.convert(Double.class, "123.123")); assertEquals(Double.NaN, DefaultTypeConverter.INSTANCE.convert(Double.class, "NaN")); assertEquals(Double.NEGATIVE_INFINITY, DefaultTypeConverter.INSTANCE.convert(Double.class, "-Infinity")); assertEquals(Double.POSITIVE_INFINITY, DefaultTypeConverter.INSTANCE.convert(Double.class, "Infinity")); assertEquals(new BigInteger("1234567890123456789"), DefaultTypeConverter.INSTANCE.convert(BigInteger.class, "1234567890123456789")); assertEquals(new BigDecimal("12345678901234567890.12345678901234567890"), DefaultTypeConverter.INSTANCE.convert(BigDecimal.class, "12345678901234567890.12345678901234567890")); GregorianCalendar cal = new GregorianCalendar(); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, 3); cal.set(Calendar.DAY_OF_MONTH, 12); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); String isoDate = ISO8601DateFormat.format(cal.getTime()); assertEquals(isoDate, ISO8601DateFormat.format(DefaultTypeConverter.INSTANCE.convert(Date.class, isoDate))); assertEquals(new Duration("P25D"), DefaultTypeConverter.INSTANCE.convert(Duration.class, "P25D")); assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String.class, "woof")); MLText converted = DefaultTypeConverter.INSTANCE.convert(MLText.class, "woof"); assertEquals("woof", converted.getValue(Locale.getDefault())); assertEquals(Locale.FRANCE, DefaultTypeConverter.INSTANCE.convert(Locale.class, "fr_FR")); assertEquals(Locale.FRANCE, DefaultTypeConverter.INSTANCE.convert(Locale.class, "fr_FR_")); assertEquals(new VersionNumber("1.2.3"), DefaultTypeConverter.INSTANCE.convert(VersionNumber.class, "1.2.3")); assertEquals(new Period("period"), DefaultTypeConverter.INSTANCE.convert(Period.class, "period")); assertEquals(new Period("period|12"), DefaultTypeConverter.INSTANCE.convert(Period.class, "period|12")); Map<String,String> periodMap = new HashMap<String, String>(); periodMap.put("periodType","month"); periodMap.put("expression","1"); assertEquals(new Period(periodMap), DefaultTypeConverter.INSTANCE.convert(Period.class, periodMap)); // Java Class assertEquals(this.getClass().getName(), DefaultTypeConverter.INSTANCE.convert(String.class, this.getClass())); }