/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* 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; either version 2.1 of the License, or (at your option)
* any later version.
*
* 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.
*/
package com.ese.ils.beta.service.impl;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.faces.model.SelectItem;
import com.ese.ils.beta.service.base.SlideLocalServiceBaseImpl;
import com.ese.ils.beta.util.DeComposer;
import com.ese.ils.beta.model.Slide;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil;
/**
* The implementation of the slide local service.
*
* <p>
* All custom service methods should be put in this class. Whenever methods are
* added, rerun ServiceBuilder to copy their definitions into the
* {@link com.ese.ils.beta.service.SlideLocalService} interface.
*
* <p>
* This is a local service. Methods of this service will not have security
* checks based on the propagated JAAS credentials because this service can only
* be accessed from within the same VM.
* </p>
*
* @author edik
* @see com.ese.ils.beta.service.base.SlideLocalServiceBaseImpl
* @see com.ese.ils.beta.service.SlideLocalServiceUtil
*/
public class SlideLocalServiceImpl extends SlideLocalServiceBaseImpl {
public FileEntry addSlideSet(File slideSet, long repositoryId,
long folderId, long moduleId) {
FileEntry fileEntry = null;
ServiceContext serviceContext = new ServiceContext();
try {
fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, folderId,
slideSet.getName(), "application/pdf", moduleId
+ " slide set",
"slides for module nr. " + moduleId, "initial upload",
slideSet, serviceContext);
} catch (Exception ex) {
ex.printStackTrace();
}
return fileEntry;
}
// add the converted png slides to the repo
public boolean addSlides(List<File> slidePNGs, long repositoryId,
long folderId, long moduleId) throws PortalException,
SystemException {
boolean status = false;
String idTemp;
// nicht null, weil array bei 0 beginnt
int slideNr = 1;
ServiceContext serviceContext = new ServiceContext();
Iterator<File> pngIterator = slidePNGs.iterator();
while (pngIterator.hasNext()) {
File slideFile = pngIterator.next();
FileEntry fileEntry = DLAppServiceUtil.addFileEntry(repositoryId,
folderId, slideFile.getName(), "image/png",
slideFile.getName(), "modul nr.: " + moduleId
+ " slide nr.: " + slideNr, "initial upload",
slideFile, serviceContext);
idTemp = DeComposer.longToPrimaryKey(moduleId,Long.valueOf(slideNr));
Slide slide = slidePersistence.create(new Long(idTemp));
slide.setModuleId(moduleId);
slide.setCreateDate(new Date());
slide.setModifiedDate(new Date());
slide.setFileEntryId(fileEntry.getFileEntryId());
slide.setAddtionalInfo("links and additional information here");
slide.setIndex(slideNr-1);
slidePersistence.update(slide, false);
slideNr++;
status = true;
}
return status;
}
public List<Slide> fetchModuleSlides(long moduleId) {
List<Slide> slideList = new ArrayList<Slide>();
try {
slideList = slidePersistence.findByByModule(moduleId);
} catch (SystemException e) {
e.printStackTrace();
}
return slideList;
}
}