001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatalists.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.language.LanguageUtil;
020    import com.liferay.portal.kernel.search.Hits;
021    import com.liferay.portal.kernel.search.Indexer;
022    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
023    import com.liferay.portal.kernel.search.SearchContext;
024    import com.liferay.portal.kernel.util.ContentTypes;
025    import com.liferay.portal.kernel.util.ListUtil;
026    import com.liferay.portal.kernel.util.OrderByComparator;
027    import com.liferay.portal.kernel.util.StringPool;
028    import com.liferay.portal.kernel.util.StringUtil;
029    import com.liferay.portal.kernel.util.Validator;
030    import com.liferay.portal.kernel.workflow.WorkflowConstants;
031    import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
032    import com.liferay.portal.model.User;
033    import com.liferay.portal.service.ServiceContext;
034    import com.liferay.portlet.documentlibrary.util.DLUtil;
035    import com.liferay.portlet.dynamicdatalists.NoSuchRecordVersionException;
036    import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
037    import com.liferay.portlet.dynamicdatalists.model.DDLRecordConstants;
038    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
039    import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion;
040    import com.liferay.portlet.dynamicdatalists.service.base.DDLRecordLocalServiceBaseImpl;
041    import com.liferay.portlet.dynamicdatalists.util.comparator.DDLRecordVersionVersionComparator;
042    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
043    import com.liferay.portlet.dynamicdatamapping.storage.Field;
044    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
045    import com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil;
046    import com.liferay.portlet.dynamicdatamapping.util.DDMUtil;
047    
048    import java.io.Serializable;
049    
050    import java.util.Collections;
051    import java.util.Date;
052    import java.util.List;
053    import java.util.Locale;
054    import java.util.Map;
055    
056    /**
057     * Provides the local service for accessing, adding, deleting, and updating
058     * dynamic data list (DDL) records.
059     *
060     * @author Marcellus Tavares
061     * @author Eduardo Lundgren
062     */
063    public class DDLRecordLocalServiceImpl extends DDLRecordLocalServiceBaseImpl {
064    
065            @Override
066            public DDLRecord addRecord(
067                            long userId, long groupId, long recordSetId, int displayIndex,
068                            Fields fields, ServiceContext serviceContext)
069                    throws PortalException, SystemException {
070    
071                    // Record
072    
073                    User user = userPersistence.findByPrimaryKey(userId);
074                    Date now = new Date();
075    
076                    DDLRecordSet recordSet = ddlRecordSetPersistence.findByPrimaryKey(
077                            recordSetId);
078    
079                    long recordId = counterLocalService.increment();
080    
081                    DDLRecord record = ddlRecordPersistence.create(recordId);
082    
083                    record.setUuid(serviceContext.getUuid());
084                    record.setGroupId(groupId);
085                    record.setCompanyId(user.getCompanyId());
086                    record.setUserId(user.getUserId());
087                    record.setUserName(user.getFullName());
088                    record.setVersionUserId(user.getUserId());
089                    record.setVersionUserName(user.getFullName());
090                    record.setCreateDate(serviceContext.getCreateDate(now));
091                    record.setModifiedDate(serviceContext.getModifiedDate(now));
092    
093                    long ddmStorageId = StorageEngineUtil.create(
094                            recordSet.getCompanyId(), recordSet.getDDMStructureId(), fields,
095                            serviceContext);
096    
097                    record.setDDMStorageId(ddmStorageId);
098    
099                    record.setRecordSetId(recordSetId);
100                    record.setVersion(DDLRecordConstants.VERSION_DEFAULT);
101                    record.setDisplayIndex(displayIndex);
102    
103                    ddlRecordPersistence.update(record);
104    
105                    // Record version
106    
107                    DDLRecordVersion recordVersion = addRecordVersion(
108                            user, record, ddmStorageId, DDLRecordConstants.VERSION_DEFAULT,
109                            displayIndex, WorkflowConstants.STATUS_DRAFT);
110    
111                    // Asset
112    
113                    Locale locale = serviceContext.getLocale();
114    
115                    updateAsset(
116                            userId, record, recordVersion, serviceContext.getAssetCategoryIds(),
117                            serviceContext.getAssetTagNames(), locale);
118    
119                    // Workflow
120    
121                    WorkflowHandlerRegistryUtil.startWorkflowInstance(
122                            user.getCompanyId(), groupId, userId, DDLRecord.class.getName(),
123                            recordVersion.getRecordVersionId(), recordVersion, serviceContext);
124    
125                    return record;
126            }
127    
128            @Override
129            public DDLRecord addRecord(
130                            long userId, long groupId, long recordSetId, int displayIndex,
131                            Map<String, Serializable> fieldsMap, ServiceContext serviceContext)
132                    throws PortalException, SystemException {
133    
134                    DDLRecordSet recordSet = ddlRecordSetPersistence.findByPrimaryKey(
135                            recordSetId);
136    
137                    DDMStructure ddmStructure = recordSet.getDDMStructure();
138    
139                    Fields fields = toFields(ddmStructure.getStructureId(), fieldsMap);
140    
141                    return addRecord(
142                            userId, groupId, recordSetId, displayIndex, fields, serviceContext);
143            }
144    
145            @Override
146            public void deleteRecord(DDLRecord record)
147                    throws PortalException, SystemException {
148    
149                    // Record
150    
151                    ddlRecordPersistence.remove(record);
152    
153                    // Record Versions
154    
155                    List<DDLRecordVersion> recordVersions =
156                            ddlRecordVersionPersistence.findByRecordId(record.getRecordId());
157    
158                    for (DDLRecordVersion recordVersion : recordVersions) {
159                            ddlRecordVersionPersistence.remove(recordVersion);
160    
161                            // Dynamic data mapping storage
162    
163                            StorageEngineUtil.deleteByClass(recordVersion.getDDMStorageId());
164    
165                            // Workflow
166    
167                            workflowInstanceLinkLocalService.deleteWorkflowInstanceLinks(
168                                    record.getCompanyId(), record.getGroupId(),
169                                    DDLRecord.class.getName(), recordVersion.getPrimaryKey());
170                    }
171    
172                    // Indexer
173    
174                    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
175                            DDLRecord.class);
176    
177                    indexer.delete(record);
178            }
179    
180            @Override
181            public void deleteRecord(long recordId)
182                    throws PortalException, SystemException {
183    
184                    DDLRecord record = ddlRecordPersistence.findByPrimaryKey(recordId);
185    
186                    deleteRecord(record);
187            }
188    
189            @Override
190            public DDLRecord deleteRecordLocale(
191                            long recordId, Locale locale, ServiceContext serviceContext)
192                    throws PortalException, SystemException {
193    
194                    DDLRecord record = ddlRecordPersistence.findByPrimaryKey(recordId);
195    
196                    Fields fields = StorageEngineUtil.getFields(record.getDDMStorageId());
197    
198                    for (Field field : fields) {
199                            Map<Locale, List<Serializable>> valuesMap = field.getValuesMap();
200    
201                            valuesMap.remove(locale);
202                    }
203    
204                    return updateRecord(
205                            serviceContext.getUserId(), recordId, false,
206                            DDLRecordConstants.DISPLAY_INDEX_DEFAULT, fields, false,
207                            serviceContext);
208            }
209    
210            @Override
211            public void deleteRecords(long recordSetId)
212                    throws PortalException, SystemException {
213    
214                    List<DDLRecord> records = ddlRecordPersistence.findByRecordSetId(
215                            recordSetId);
216    
217                    for (DDLRecord record : records) {
218                            deleteRecord(record);
219                    }
220            }
221    
222            @Override
223            public DDLRecord fetchRecord(long recordId) throws SystemException {
224                    return ddlRecordPersistence.fetchByPrimaryKey(recordId);
225            }
226    
227            @Override
228            public List<DDLRecord> getCompanyRecords(
229                            long companyId, int status, int scope, int start, int end,
230                            OrderByComparator orderByComparator)
231                    throws SystemException {
232    
233                    return ddlRecordFinder.findByC_S_S(
234                            companyId, status, scope, start, end, orderByComparator);
235            }
236    
237            /**
238             * @deprecated As of 6.2.0, replaced by {@link #getCompanyRecords(long, int,
239             *             int, int, int, OrderByComparator)}
240             */
241            @Override
242            public List<DDLRecord> getCompanyRecords(
243                            long companyId, int scope, int start, int end,
244                            OrderByComparator orderByComparator)
245                    throws SystemException {
246    
247                    return getCompanyRecords(
248                            companyId, WorkflowConstants.STATUS_ANY, scope, start, end,
249                            orderByComparator);
250            }
251    
252            /**
253             * @deprecated As of 6.2.0, replaced by {@link #getCompanyRecordsCount(long,
254             *             int, int)}
255             */
256            @Override
257            public int getCompanyRecordsCount(long companyId, int scope)
258                    throws SystemException {
259    
260                    return getCompanyRecordsCount(
261                            companyId, WorkflowConstants.STATUS_ANY, scope);
262            }
263    
264            @Override
265            public int getCompanyRecordsCount(long companyId, int status, int scope)
266                    throws SystemException {
267    
268                    return ddlRecordFinder.countByC_S_S(companyId, status, scope);
269            }
270    
271            @Override
272            public DDLRecordVersion getLatestRecordVersion(long recordId)
273                    throws PortalException, SystemException {
274    
275                    List<DDLRecordVersion> recordVersions =
276                            ddlRecordVersionPersistence.findByRecordId(recordId);
277    
278                    if (recordVersions.isEmpty()) {
279                            throw new NoSuchRecordVersionException(
280                                    "No record versions found for recordId " + recordId);
281                    }
282    
283                    recordVersions = ListUtil.copy(recordVersions);
284    
285                    Collections.sort(
286                            recordVersions, new DDLRecordVersionVersionComparator());
287    
288                    return recordVersions.get(0);
289            }
290    
291            @Override
292            public Long[] getMinAndMaxCompanyRecordIds(
293                            long companyId, int status, int scope)
294                    throws SystemException {
295    
296                    return ddlRecordFinder.findByC_S_S_MinAndMax(companyId, status, scope);
297            }
298    
299            @Override
300            public List<DDLRecord> getMinAndMaxCompanyRecords(
301                            long companyId, int status, int scope, long minRecordId,
302                            long maxRecordId)
303                    throws SystemException {
304    
305                    return ddlRecordFinder.findByC_S_S_MinAndMax(
306                            companyId, status, scope, minRecordId, maxRecordId);
307            }
308    
309            @Override
310            public DDLRecord getRecord(long recordId)
311                    throws PortalException, SystemException {
312    
313                    return ddlRecordPersistence.findByPrimaryKey(recordId);
314            }
315    
316            @Override
317            public List<DDLRecord> getRecords(long recordSetId) throws SystemException {
318                    return ddlRecordPersistence.findByRecordSetId(recordSetId);
319            }
320    
321            @Override
322            public List<DDLRecord> getRecords(
323                            long recordSetId, int status, int start, int end,
324                            OrderByComparator orderByComparator)
325                    throws SystemException {
326    
327                    return ddlRecordFinder.findByR_S(
328                            recordSetId, status, start, end, orderByComparator);
329            }
330    
331            @Override
332            public List<DDLRecord> getRecords(long recordSetId, long userId)
333                    throws SystemException {
334    
335                    return ddlRecordPersistence.findByR_U(recordSetId, userId);
336            }
337    
338            @Override
339            public int getRecordsCount(long recordSetId, int status)
340                    throws SystemException {
341    
342                    return ddlRecordFinder.countByR_S(recordSetId, status);
343            }
344    
345            @Override
346            public DDLRecordVersion getRecordVersion(long recordVersionId)
347                    throws PortalException, SystemException {
348    
349                    return ddlRecordVersionPersistence.findByPrimaryKey(recordVersionId);
350            }
351    
352            @Override
353            public DDLRecordVersion getRecordVersion(long recordId, String version)
354                    throws PortalException, SystemException {
355    
356                    return ddlRecordVersionPersistence.findByR_V(recordId, version);
357            }
358    
359            @Override
360            public List<DDLRecordVersion> getRecordVersions(
361                            long recordId, int start, int end,
362                            OrderByComparator orderByComparator)
363                    throws SystemException {
364    
365                    return ddlRecordVersionPersistence.findByRecordId(
366                            recordId, start, end, orderByComparator);
367            }
368    
369            @Override
370            public int getRecordVersionsCount(long recordId) throws SystemException {
371                    return ddlRecordVersionPersistence.countByRecordId(recordId);
372            }
373    
374            @Override
375            public void revertRecordVersion(
376                            long userId, long recordId, String version,
377                            ServiceContext serviceContext)
378                    throws PortalException, SystemException {
379    
380                    DDLRecordVersion recordVersion = getRecordVersion(recordId, version);
381    
382                    if (!recordVersion.isApproved()) {
383                            return;
384                    }
385    
386                    Fields fields = StorageEngineUtil.getFields(
387                            recordVersion.getDDMStorageId());
388    
389                    updateRecord(
390                            userId, recordId, true, recordVersion.getDisplayIndex(), fields,
391                            false, serviceContext);
392            }
393    
394            @Override
395            public Hits search(SearchContext searchContext) throws SystemException {
396                    try {
397                            Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
398                                    DDLRecord.class);
399    
400                            return indexer.search(searchContext);
401                    }
402                    catch (Exception e) {
403                            throw new SystemException(e);
404                    }
405            }
406    
407            @Override
408            public void updateAsset(
409                            long userId, DDLRecord record, DDLRecordVersion recordVersion,
410                            long[] assetCategoryIds, String[] assetTagNames, Locale locale)
411                    throws PortalException, SystemException {
412    
413                    boolean addDraftAssetEntry = false;
414    
415                    if ((recordVersion != null) && !recordVersion.isApproved()) {
416                            String version = recordVersion.getVersion();
417    
418                            if (!version.equals(DDLRecordConstants.VERSION_DEFAULT)) {
419                                    int approvedRecordVersionsCount =
420                                            ddlRecordVersionPersistence.countByR_S(
421                                                    record.getRecordId(),
422                                                    WorkflowConstants.STATUS_APPROVED);
423    
424                                    if (approvedRecordVersionsCount > 0) {
425                                            addDraftAssetEntry = true;
426                                    }
427                            }
428                    }
429    
430                    boolean visible = false;
431    
432                    if ((recordVersion != null) && !recordVersion.isApproved()) {
433                            visible = false;
434                    }
435    
436                    DDLRecordSet recordSet = record.getRecordSet();
437    
438                    DDMStructure ddmStructure = recordSet.getDDMStructure();
439    
440                    String ddmStructureName = ddmStructure.getName(locale);
441    
442                    String recordSetName = recordSet.getName(locale);
443    
444                    String title = LanguageUtil.format(
445                            locale, "new-x-for-list-x",
446                            new Object[] {ddmStructureName, recordSetName});
447    
448                    if (addDraftAssetEntry) {
449                            assetEntryLocalService.updateEntry(
450                                    userId, record.getGroupId(), record.getCreateDate(),
451                                    record.getModifiedDate(), DDLRecordConstants.getClassName(),
452                                    recordVersion.getRecordVersionId(), record.getUuid(), 0,
453                                    assetCategoryIds, assetTagNames, false, null, null, null,
454                                    ContentTypes.TEXT_HTML, title, null, StringPool.BLANK, null,
455                                    null, 0, 0, null, false);
456                    }
457                    else {
458                            assetEntryLocalService.updateEntry(
459                                    userId, record.getGroupId(), record.getCreateDate(),
460                                    record.getModifiedDate(), DDLRecordConstants.getClassName(),
461                                    record.getRecordId(), record.getUuid(), 0, assetCategoryIds,
462                                    assetTagNames, visible, null, null, null,
463                                    ContentTypes.TEXT_HTML, title, null, StringPool.BLANK, null,
464                                    null, 0, 0, null, false);
465                    }
466            }
467    
468            @Override
469            public DDLRecord updateRecord(
470                            long userId, long recordId, boolean majorVersion, int displayIndex,
471                            Fields fields, boolean mergeFields, ServiceContext serviceContext)
472                    throws PortalException, SystemException {
473    
474                    // Record
475    
476                    User user = userPersistence.findByPrimaryKey(userId);
477    
478                    DDLRecord record = ddlRecordPersistence.findByPrimaryKey(recordId);
479    
480                    record.setModifiedDate(serviceContext.getModifiedDate(null));
481    
482                    ddlRecordPersistence.update(record);
483    
484                    // Record version
485    
486                    DDLRecordVersion recordVersion = record.getLatestRecordVersion();
487    
488                    if (recordVersion.isApproved()) {
489                            DDLRecordSet recordSet = record.getRecordSet();
490    
491                            if (mergeFields) {
492                                    Fields existingFields = StorageEngineUtil.getFields(
493                                            recordVersion.getDDMStorageId());
494    
495                                    fields = DDMUtil.mergeFields(fields, existingFields);
496                            }
497    
498                            long ddmStorageId = StorageEngineUtil.create(
499                                    recordSet.getCompanyId(), recordSet.getDDMStructureId(), fields,
500                                    serviceContext);
501                            String version = getNextVersion(
502                                    recordVersion.getVersion(), majorVersion,
503                                    serviceContext.getWorkflowAction());
504    
505                            recordVersion = addRecordVersion(
506                                    user, record, ddmStorageId, version, displayIndex,
507                                    WorkflowConstants.STATUS_DRAFT);
508                    }
509                    else {
510                            StorageEngineUtil.update(
511                                    recordVersion.getDDMStorageId(), fields, mergeFields,
512                                    serviceContext);
513    
514                            String version = recordVersion.getVersion();
515    
516                            updateRecordVersion(
517                                    user, recordVersion, version, displayIndex,
518                                    recordVersion.getStatus(), serviceContext);
519                    }
520    
521                    // Workflow
522    
523                    WorkflowHandlerRegistryUtil.startWorkflowInstance(
524                            user.getCompanyId(), record.getGroupId(), userId,
525                            DDLRecord.class.getName(), recordVersion.getRecordVersionId(),
526                            recordVersion, serviceContext);
527    
528                    return record;
529            }
530    
531            @Override
532            public DDLRecord updateRecord(
533                            long userId, long recordId, int displayIndex,
534                            Map<String, Serializable> fieldsMap, boolean mergeFields,
535                            ServiceContext serviceContext)
536                    throws PortalException, SystemException {
537    
538                    DDLRecord record = ddlRecordPersistence.findByPrimaryKey(recordId);
539    
540                    DDLRecordSet recordSet = record.getRecordSet();
541    
542                    DDMStructure ddmStructure = recordSet.getDDMStructure();
543    
544                    Fields fields = toFields(ddmStructure.getStructureId(), fieldsMap);
545    
546                    return updateRecord(
547                            userId, recordId, false, displayIndex, fields, mergeFields,
548                            serviceContext);
549            }
550    
551            @Override
552            public DDLRecord updateStatus(
553                            long userId, long recordVersionId, int status,
554                            ServiceContext serviceContext)
555                    throws PortalException, SystemException {
556    
557                    // Record version
558    
559                    User user = userPersistence.findByPrimaryKey(userId);
560    
561                    DDLRecordVersion recordVersion =
562                            ddlRecordVersionPersistence.findByPrimaryKey(recordVersionId);
563    
564                    recordVersion.setStatus(status);
565                    recordVersion.setStatusByUserId(user.getUserId());
566                    recordVersion.setStatusByUserName(user.getFullName());
567                    recordVersion.setStatusDate(new Date());
568    
569                    ddlRecordVersionPersistence.update(recordVersion);
570    
571                    // Record
572    
573                    DDLRecord record = ddlRecordPersistence.findByPrimaryKey(
574                            recordVersion.getRecordId());
575    
576                    if (status == WorkflowConstants.STATUS_APPROVED) {
577                            if (DLUtil.compareVersions(
578                                            record.getVersion(), recordVersion.getVersion()) <= 0) {
579    
580                                    record.setDDMStorageId(recordVersion.getDDMStorageId());
581                                    record.setVersion(recordVersion.getVersion());
582                                    record.setRecordSetId(recordVersion.getRecordSetId());
583                                    record.setDisplayIndex(recordVersion.getDisplayIndex());
584                                    record.setVersion(recordVersion.getVersion());
585                                    record.setVersionUserId(recordVersion.getUserId());
586                                    record.setVersionUserName(recordVersion.getUserName());
587                                    record.setModifiedDate(recordVersion.getCreateDate());
588    
589                                    ddlRecordPersistence.update(record);
590                            }
591                    }
592                    else {
593                            if (Validator.equals(
594                                            record.getVersion(), recordVersion.getVersion())) {
595    
596                                    String newVersion = DDLRecordConstants.VERSION_DEFAULT;
597    
598                                    List<DDLRecordVersion> approvedRecordVersions =
599                                            ddlRecordVersionPersistence.findByR_S(
600                                                    record.getRecordId(),
601                                                    WorkflowConstants.STATUS_APPROVED);
602    
603                                    if (!approvedRecordVersions.isEmpty()) {
604                                            newVersion = approvedRecordVersions.get(0).getVersion();
605                                    }
606    
607                                    record.setVersion(newVersion);
608    
609                                    ddlRecordPersistence.update(record);
610                            }
611    
612                            // Indexer
613    
614                            if (Validator.equals(
615                                            recordVersion.getVersion(),
616                                            DDLRecordConstants.VERSION_DEFAULT)) {
617    
618                                    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
619                                            DDLRecord.class);
620    
621                                    indexer.delete(record);
622                            }
623                    }
624    
625                    // Indexer
626    
627                    if (status == WorkflowConstants.STATUS_APPROVED) {
628                            Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
629                                    DDLRecord.class);
630    
631                            indexer.reindex(record);
632                    }
633    
634                    return record;
635            }
636    
637            protected DDLRecordVersion addRecordVersion(
638                            User user, DDLRecord record, long ddmStorageId, String version,
639                            int displayIndex, int status)
640                    throws SystemException {
641    
642                    long recordVersionId = counterLocalService.increment();
643    
644                    DDLRecordVersion recordVersion = ddlRecordVersionPersistence.create(
645                            recordVersionId);
646    
647                    recordVersion.setGroupId(record.getGroupId());
648                    recordVersion.setCompanyId(record.getCompanyId());
649                    recordVersion.setUserId(user.getUserId());
650                    recordVersion.setUserName(user.getFullName());
651                    recordVersion.setCreateDate(record.getModifiedDate());
652                    recordVersion.setDDMStorageId(ddmStorageId);
653                    recordVersion.setRecordSetId(record.getRecordSetId());
654                    recordVersion.setRecordId(record.getRecordId());
655                    recordVersion.setVersion(version);
656                    recordVersion.setDisplayIndex(displayIndex);
657                    recordVersion.setStatus(status);
658                    recordVersion.setStatusByUserId(user.getUserId());
659                    recordVersion.setStatusByUserName(user.getFullName());
660                    recordVersion.setStatusDate(record.getModifiedDate());
661    
662                    ddlRecordVersionPersistence.update(recordVersion);
663    
664                    return recordVersion;
665            }
666    
667            protected String getNextVersion(
668                    String version, boolean majorVersion, int workflowAction) {
669    
670                    if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) {
671                            majorVersion = false;
672                    }
673    
674                    int[] versionParts = StringUtil.split(version, StringPool.PERIOD, 0);
675    
676                    if (majorVersion) {
677                            versionParts[0]++;
678                            versionParts[1] = 0;
679                    }
680                    else {
681                            versionParts[1]++;
682                    }
683    
684                    return versionParts[0] + StringPool.PERIOD + versionParts[1];
685            }
686    
687            protected Fields toFields(
688                    long ddmStructureId, Map<String, Serializable> fieldsMap) {
689    
690                    Fields fields = new Fields();
691    
692                    for (String name : fieldsMap.keySet()) {
693                            String value = String.valueOf(fieldsMap.get(name));
694    
695                            Field field = new Field(ddmStructureId, name, value);
696    
697                            fields.put(field);
698                    }
699    
700                    return fields;
701            }
702    
703            protected void updateRecordVersion(
704                            User user, DDLRecordVersion recordVersion, String version,
705                            int displayIndex, int status, ServiceContext serviceContext)
706                    throws SystemException {
707    
708                    recordVersion.setUserId(user.getUserId());
709                    recordVersion.setUserName(user.getFullName());
710                    recordVersion.setVersion(version);
711                    recordVersion.setDisplayIndex(displayIndex);
712                    recordVersion.setStatus(status);
713                    recordVersion.setStatusByUserId(user.getUserId());
714                    recordVersion.setStatusByUserName(user.getFullName());
715                    recordVersion.setStatusDate(serviceContext.getModifiedDate(null));
716    
717                    ddlRecordVersionPersistence.update(recordVersion);
718            }
719    
720    }