private void setChanges( Instance dest, Instance src, Function<Instance, Instance> oldFunction, long[] changes, boolean isInput) { AModelType type = InvocationContext.get().getTypeManager().getByPrefix(dest._type()); List<AIField> fields = type.getAllFields(); for (AIField f : fields) { if (f.getName().equals("id")) { dest._setId(src.getId()); continue; } // If this field changed int index = dest._getPropertyIndex(f.getName()); if (InstanceImpl._hasBit(changes, index)) { if (f.isChild()) { setChildValue(dest, src, f, oldFunction, isInput); } else { Property<?> property = src._get(f.getName()); if (property == null) { continue; } dest._set(f.getName(), property.getValue()); } dest._markChange(index, null, null); } } }
private static String createScheduleJOB( String JobName, String cronExpression, Schedulable schedulable_class, TimeZone timeZone, DateTime startTime) { VirtualServerExecution start = VirtualServerExecution.start(); try { CronTrigger cron = AModelType.newInstanceOfType(SO.CRON_TRIGGER); cron.setName(JobName); cron.setRunAs(InvocationContext.get().getCurrentSession().getUser()); cron.setStartTime(startTime); cron.setPattern(cronExpression); cron.setSchedulable(schedulable_class); if (timeZone == null) { cron.setTimeZone(InvocationContext.get().getUser().getUserTimeZone()); } else { cron.setTimeZone(timeZone); } cron.setNextFireTime( DateTime.newInstance( NextScheduleProvider.nextSchedule(cron.getPattern(), cron.getTimeZone()))); DBResult insert = Database.insert(cron, new DMLOptions(DMLOperationType.THROW_ERRORS)); return String.valueOf(insert._getId()); } finally { start.finish(); } }
private static UploadedPackageMember createUploadedMembership( Instance component, PackageMember member, PackageVersion version) { // Create Uploaded Package Membership with cloned component UploadedPackageMember uploadMembership = AModelType.newInstanceOfType(SO.UPLOADED_PACKAGE_MEMBER); uploadMembership.setPackaze(version.getPackaze()); uploadMembership.setPackageVersion(version); uploadMembership.setComponent(component); uploadMembership.setPackageMember(member); return uploadMembership; }