All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bonitasoft.engine.api.impl.converter.PageModelConverter Maven / Gradle / Ivy

There is a newer version: 10.2.0
Show newest version
/**
 * Copyright (C) 2015 BonitaSoft S.A.
 * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation
 * version 2.1 of the License.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301, USA.
 **/
package org.bonitasoft.engine.api.impl.converter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.bonitasoft.engine.builder.BuilderFactory;
import org.bonitasoft.engine.page.Page;
import org.bonitasoft.engine.page.PageCreator;
import org.bonitasoft.engine.page.PageUpdater;
import org.bonitasoft.engine.page.SPage;
import org.bonitasoft.engine.page.SPageBuilder;
import org.bonitasoft.engine.page.SPageBuilderFactory;
import org.bonitasoft.engine.page.impl.PageImpl;

/**
 * @author Elias Ricken de Medeiros
 */
public class PageModelConverter {

    public SPage constructSPage(final PageCreator pageCreator, final long creatorUserId) {
        final Map fields = pageCreator.getFields();
        final String name = (String) fields.get(PageCreator.PageField.NAME);
        final String description = (String) fields.get(PageCreator.PageField.DESCRIPTION);
        final String displayName = (String) fields.get(PageCreator.PageField.DISPLAY_NAME);
        final String contentName = (String) fields.get(PageCreator.PageField.CONTENT_NAME);
        final String contentType = (String) fields.get(PageCreator.PageField.CONTENT_TYPE);
        final Long processDefinitionId = (Long) fields.get(PageCreator.PageField.PROCESS_DEFINITION_ID);
        Boolean hidden = (Boolean) fields.get(PageCreator.PageField.HIDDEN);
        if (hidden == null) {
            hidden = false;
        }
        return buildSPage(creatorUserId, name, description, displayName, contentName, contentType, processDefinitionId, hidden);
    }

    public SPage constructSPage(final PageUpdater pageUpdater, final long creatorUserId) {
        final Map fields = pageUpdater.getFields();
        final String name = (String) fields.get(PageUpdater.PageUpdateField.NAME);
        final String description = (String) fields.get(PageUpdater.PageUpdateField.DESCRIPTION);
        final String displayName = (String) fields.get(PageUpdater.PageUpdateField.DISPLAY_NAME);
        final String contentName = (String) fields.get(PageUpdater.PageUpdateField.CONTENT_NAME);
        final String contentType = (String) fields.get(PageUpdater.PageUpdateField.CONTENT_TYPE);
        final Long processDefinitionId = (Long) fields.get(PageUpdater.PageUpdateField.PROCESS_DEFINITION_ID);
        Boolean hidden = (Boolean) fields.get(PageUpdater.PageUpdateField.HIDDEN);
        if (hidden == null) {
            hidden = false;
        }
        return buildSPage(creatorUserId, name, description, displayName, contentName, contentType, processDefinitionId, hidden);
    }

    private SPage buildSPage(long creatorUserId, String name, String description, String displayName, String contentName, String contentType,
            Long processDefinitionId, boolean hidden) {
        final SPageBuilder newSPageBuilder = BuilderFactory.get(SPageBuilderFactory.class).createNewInstance(name, description, displayName,
                System.currentTimeMillis(), creatorUserId, false, hidden, contentName);
        newSPageBuilder.setContentType(contentType);
        newSPageBuilder.setProcessDefinitionId(processDefinitionId);
        return newSPageBuilder.done();
    }

    public Page toPage(final SPage sPage) {
        Long processDefinitionId = sPage.getProcessDefinitionId() > 0 ? sPage.getProcessDefinitionId() : null;
        return new PageImpl(sPage.getId(), sPage.getName(), sPage.getDisplayName(), sPage.isProvided(), sPage.isHidden(), sPage.getDescription(),
                sPage.getInstallationDate(), sPage.getInstalledBy(), sPage.getLastModificationDate(), sPage.getLastUpdatedBy(), sPage.getContentName(),
                sPage.getContentType(), processDefinitionId);
    }

    public List toPages(final List sPages) {
        final List pages = new ArrayList<>(sPages.size());
        for (final SPage sPage : sPages) {
            pages.add(toPage(sPage));
        }
        return pages;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy