List of usage examples for org.apache.commons.lang3.reflect FieldUtils writeDeclaredField
public static void writeDeclaredField(final Object target, final String fieldName, final Object value, final boolean forceAccess) throws IllegalAccessException
From source file:eu.europa.ec.fisheries.uvms.spatial.service.entity.BaseAreaEntity.java
public BaseAreaEntity(Map<String, Object> values, List<UploadMappingProperty> mapping) throws ServiceException { try {/*from w w w .jav a2 s. co m*/ geom = (Geometry) values.get("the_geom"); // shape file standard enabled = true; enabledOn = new Date(); if (mapping != null) { for (UploadMappingProperty property : mapping) { Object value = values.get(property.getTarget()); if ("code".equals(property.getSource())) { if (value != null) { code = String.valueOf(value); } } else if ("name".equals(property.getSource())) { if (value != null) { name = String.valueOf(value); } } else { FieldUtils.writeDeclaredField(this, property.getSource(), value, true); } } } } catch (IllegalAccessException e) { throw new ServiceException("ERROR WHILE MAPPING ENTITY", e); } }
From source file:atg.tools.dynunit.nucleus.NucleusUtils.java
/** * Allows the absoluteName of the given service to be explicitly defined. * Normally this is determined by the object's location in the Nucleus * hierarchy. For test items that are not really bound to Nucleus, it's * convenient to just give it an absolute name rather than going through * the whole configuration and binding process. * * @param absoluteName// ww w . java 2 s .c om * The absolute name value to set * @param service * The service whose absolute name should be set. */ public static void setAbsoluteName(String absoluteName, GenericService service) throws IllegalAccessException { FieldUtils.writeDeclaredField(service, "mAbsoluteName", absoluteName, true); }
From source file:com.xpn.xwiki.store.XWikiHibernateRecycleBinStore.java
private XWikiDeletedDocument resolveDeletedDocumentContent(XWikiDeletedDocument deletedDocument, boolean bTransaction) throws XWikiException { XWikiRecycleBinContentStoreInterface contentStore = getXWikiRecycleBinContentStore( deletedDocument.getXmlStore()); if (contentStore != null) { DocumentReference reference = deletedDocument.getDocumentReference(); XWikiDeletedDocumentContent content = contentStore.get(reference, deletedDocument.getId(), bTransaction);// www. j a v a 2 s . co m try { FieldUtils.writeDeclaredField(deletedDocument, "xml", content, true); } catch (IllegalAccessException e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Failed to set deleted document content", e); } } return deletedDocument; }
From source file:net.sourceforge.pmd.cli.PMDParametersTest.java
@Test public void testVersion() throws Exception { PMDParameters parameters = new PMDParameters(); // no language set, uses default language Assert.assertEquals("1.7", parameters.getVersion()); // now set lanuage FieldUtils.writeDeclaredField(parameters, "language", "dummy2", true); Assert.assertEquals("1.0", parameters.getVersion()); }
From source file:org.apache.usergrid.persistence.model.field.EntityTest.java
@Test public void testPutAndGet() throws IllegalAccessException { final UUID uuid = UUIDGenerator.newTimeUUID(); final UUID version = UUIDGenerator.newTimeUUID(); final String type = "test"; final Id simpleId = new SimpleId(uuid, type); Entity entity = new Entity(simpleId); FieldUtils.writeDeclaredField(entity, "version", version, true); assertEquals(uuid, entity.getId().getUuid()); assertEquals(type, entity.getId().getType()); assertEquals(version, entity.getVersion()); BooleanField boolField = new BooleanField("boolean", false); DoubleField doubleField = new DoubleField("double", 1d); IntegerField intField = new IntegerField("long", 1); LongField longField = new LongField("int", 1l); StringField stringField = new StringField("name", "test"); UUIDField uuidField = new UUIDField("uuid", UUIDGenerator.newTimeUUID()); NullField nullField = new NullField("null"); entity.setField(boolField);// ww w . ja v a 2 s.co m entity.setField(doubleField); entity.setField(intField); entity.setField(longField); entity.setField(stringField); entity.setField(uuidField); entity.setField(nullField); Field<Boolean> boolFieldReturned = entity.getField(boolField.getName()); assertSame(boolField, boolFieldReturned); Field<Double> doubleFieldReturned = entity.getField(doubleField.getName()); assertSame(doubleField, doubleFieldReturned); Field<Integer> intFieldReturned = entity.getField(intField.getName()); assertSame(intField, intFieldReturned); Field<Long> longFieldReturned = entity.getField(longField.getName()); assertSame(longField, longFieldReturned); Field<String> stringFieldReturned = entity.getField(stringField.getName()); assertSame(stringField, stringFieldReturned); Field<UUID> uuidFieldReturned = entity.getField(uuidField.getName()); assertSame(uuidField, uuidFieldReturned); Field<Object> nullFieldReturned = entity.getField(nullField.getName()); assertSame(nullField, nullFieldReturned); Set<Field> results = new HashSet<Field>(); results.addAll(entity.getFields()); assertTrue(results.contains(boolField)); assertTrue(results.contains(doubleField)); assertTrue(results.contains(intField)); assertTrue(results.contains(longField)); assertTrue(results.contains(stringField)); assertTrue(results.contains(uuidField)); assertTrue(results.contains(nullField)); assertEquals(7, results.size()); assertEquals(simpleId, entity.getId()); assertEquals(version, entity.getVersion()); }
From source file:org.silverpeas.core.calendar.CalendarEventOccurrenceGenerationTest.java
private static List<CalendarEvent> calendarEventsForTest() { List<CalendarEvent> events = new ArrayList<>(); /* event 1 on Thursday 2016-08-11 */ events.add(CalendarEvent.on(date(2016, 8, 11)).withTitle(EVENT_TITLE + " 1") .withDescription(EVENT_DESCRIPTION + " 1").withAttribute(ATTR_TEST_ID, "1")); /* event 2 at Friday 2016-05-20 15h00 - 15h35 */ events.add(CalendarEvent//from w w w. j a va2s .co m .on(Period.between(dateTimeInUTC(2016, 5, 20, 15, 0), dateTimeInUTC(2016, 5, 20, 15, 35))) .withTitle(EVENT_TITLE + " 2").withDescription(EVENT_DESCRIPTION + " 2") .withAttribute(ATTR_TEST_ID, "2")); /* event 3 at 09h00 - 09h15 every Fridays from 2016-03-04 excluding Friday 2016-07-15 and Friday 2016-07-22 */ events.add( CalendarEvent.on(Period.between(dateTimeInUTC(2016, 3, 4, 9, 0), dateTimeInUTC(2016, 3, 4, 9, 15))) .withTitle(EVENT_TITLE + " 3").withDescription(EVENT_DESCRIPTION + " 3") .withAttribute(ATTR_TEST_ID, "3").recur(Recurrence.every(WEEK).on(FRIDAY) .excludeEventOccurrencesStartingAt(date(2016, 7, 15), date(2016, 7, 22)))); /* event 4 from Monday 2016-07-11 to Friday 2016-07-22 */ events.add( CalendarEvent.on(Period.between(date(2016, 7, 11), date(2016, 7, 22))).withTitle(EVENT_TITLE + " 4") .withDescription(EVENT_DESCRIPTION + " 4").withAttribute(ATTR_TEST_ID, "4")); /* event 5 at 10h00 - 11h00 every Monday, Tuesday and Wednesday from Thursday 2016-09-01 to Tuesday 2016-12-20 excluding Wednesday 2016-11-30 and Monday 2016-12-12 */ events.add( CalendarEvent.on(Period.between(dateTimeInUTC(2016, 9, 1, 10, 0), dateTimeInUTC(2016, 9, 1, 11, 0))) .withTitle(EVENT_TITLE + " 5").withDescription(EVENT_DESCRIPTION + " 5") .withAttribute(ATTR_TEST_ID, "5") .recur(Recurrence.every(WEEK).on(MONDAY, TUESDAY, WEDNESDAY) .until(dateTimeInUTC(2016, 12, 20, 10, 0)) .excludeEventOccurrencesStartingAt(date(2016, 11, 30), date(2016, 12, 12)))); /* event 6 at 08h00 - 09h00 every month on all Thursdays and on the third Friday from Thursday 2016-04-28 to Friday 2016-07-01 */ events.add( CalendarEvent.on(Period.between(dateTimeInUTC(2016, 4, 28, 8, 0), dateTimeInUTC(2016, 4, 28, 9, 0))) .withTitle(EVENT_TITLE + " 6").withDescription(EVENT_DESCRIPTION + " 6") .withAttribute(ATTR_TEST_ID, "6") .recur(Recurrence.every(MONTH) .on(DayOfWeekOccurrence.all(THURSDAY), DayOfWeekOccurrence.nth(3, FRIDAY)) .until(date(2016, 6, 30)))); Calendar calendar = new Calendar(); calendar.setZoneId(UTC_ZONE_ID); for (CalendarEvent event : events) { try { FieldUtils.writeDeclaredField(event.asCalendarComponent(), "calendar", calendar, true); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } return events; }
From source file:org.silverpeas.core.calendar.CalendarEventOccurrenceGenerationTest.java
private CalendarEvent calendarEventForTest(Period period, ZoneId calendarZoneId) { CalendarEvent event = CalendarEvent.on(period).withTitle(EVENT_TITLE).withDescription(EVENT_DESCRIPTION); Calendar calendar = new Calendar(); calendar.setZoneId(calendarZoneId);/*from ww w . j ava2 s. c om*/ try { FieldUtils.writeDeclaredField(event.asCalendarComponent(), "calendar", calendar, true); } catch (IllegalAccessException e) { throw new RuntimeException(e); } return event; }