Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
#102 favicon.ico, simplification, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
srose committed Feb 22, 2020
1 parent 7c7800f commit a77f1a4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 45 deletions.
16 changes: 9 additions & 7 deletions converters/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Beside the conference data in dukecon format, images for speakers are extracted.

Example use:
-----
java -jar dukecon-server-converters-1.6-static-SNAPSHOT.jar file:conferences-javaland.yml ./img
java -jar dukecon-server-converters-1.6-static-SNAPSHOT.jar file:conferences-javaland.yml ./resources
-----

=== Input
Expand All @@ -21,8 +21,8 @@ java -jar dukecon-server-converters-1.6-static-SNAPSHOT.jar file:conferences-jav
The project *dukecon_resources* contains all configurations.

|2
|resources-path
|In this path the listed input is taken as given
|resources-folder
|In this folder the listed input is taken as given
[%header,cols="1,1"]
!=======
!name
Expand All @@ -43,12 +43,14 @@ The project *dukecon_resources* contains all configurations.
|Initialization-file for pwa-dukecon-client
|htdocs/rest/<conference>/<year>/rest/image-resources.json
|Image data for core images for a conference (e.g. logo, etc.)
|htdocs/rest/<conference>/<year>/rest/styles.css
|Styledefinitions for a conference
|htdocs/rest/<conference>/<year>/rest/conferences/<conferenceId>.json
|Conference Data in Dukecon-format
|htdocs/rest/<conference>/<year>/rest/speaker/images/<md5>.<type>
|List of images relevant for at least one conference
|htdocs/rest/<conference>/<year>/rest/speaker/images/<md5>
|Images of speakers, each image is relevant for at least one conference
|htdocs/rest/<conference>/<year>/styles.css
|Styledefinitions for a conference
|htdocs/rest/<conference>/<year>/img/favicon.ico
|favicon.ico für den Browser
|tempbackupdir/<conferenceId>/<resource>.json
|Backup of resources given in given conferences.xml as input
|=======
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GenerateDukecon {
log.error("Error calling '{}': {} {}", GenerateDukecon.class, msg)
}
log.info("Usage: {} <conferenceUrl> <resourcesFolder>", GenerateDukecon.class)
log.info("Example: {} file:conferences.yml ./resources", GenerateDukecon.class)
log.info("Example: {} file:conferences.yml .${File.separator}resources", GenerateDukecon.class)
if (exitCode) {
System.exit(exitCode)
}
Expand All @@ -40,13 +40,13 @@ class GenerateDukecon {
}

String inputUrlConferenceConfigFile = args[0]
String inputPathForImageResourcesJson = "${args[1]}/public/img"
String inputTemplateFileForStyleCss = "${args[1]}/templates/styles.gtl"
String inputPathForImageResourcesJson = "${args[1]}${File.separator}public${File.separator}img"
String inputTemplateFileForStyleCss = "${args[1]}${File.separator}templates${File.separator}styles.gtl"

ConferencesConfiguration conferencesConfiguration = ConferencesConfiguration.fromFile(inputUrlConferenceConfigFile, [:], false)
conferencesConfiguration.conferences.each { ConferencesConfiguration.Conference conferenceConfig ->

String outputConferenceStartDirectoryName = "htdocs/rest/${conferenceConfig.conference}/${conferenceConfig.year}/rest"
String outputConferenceStartDirectoryName = "htdocs${File.separator}rest${File.separator}${conferenceConfig.conference}${File.separator}${conferenceConfig.year}"

RawDataResources rawDataResources = RawDataResources.of(conferenceConfig)
Class rawDataMapperClass = conferenceConfig.rawDataMapperClass as Class
Expand All @@ -68,30 +68,45 @@ class GenerateDukecon {

Conference conference = conferenceDataExtractor.conference

String outputFileConferenceJson = "${outputConferenceStartDirectoryName}/conferences/${conferenceConfig.id}.json"
String outputFileConferenceJson = "${outputConferenceStartDirectoryName}${File.separator}rest${File.separator}conferences${File.separator}${conferenceConfig.id}.json"
ObjectMapper objectMapper = new ObjectMapper()
File conferenceJson = new File(outputFileConferenceJson)
conferenceJson.getParentFile().mkdirs()
objectMapper.writeValue(conferenceJson, conference)
log.info("Created {}", conferenceJson.absolutePath)

File initJson = new File("${outputConferenceStartDirectoryName}/init.json")
File initJson = new File("${outputConferenceStartDirectoryName}${File.separator}rest${File.separator}init.json")
objectMapper.writeValue(initJson, getInitJsonContent(conferenceConfig))
log.info("Created {}", initJson.absolutePath)

File imageResourcesJson = new File("${outputConferenceStartDirectoryName}/image-resources.json")
objectMapper.writeValue(imageResourcesJson, getImageResourcesJsonContent(inputPathForImageResourcesJson, conferenceConfig.id))
File imageResourcesJson = new File("${outputConferenceStartDirectoryName}${File.separator}rest${File.separator}image-resources.json")
def imageResourcesJsonContent = getImageResourcesJsonContent(inputPathForImageResourcesJson, conferenceConfig.id)
objectMapper.writeValue(imageResourcesJson, imageResourcesJsonContent)
log.info("Created {}", imageResourcesJson.absolutePath)

def cssStyles = generateStylesCssContent(conferenceConfig, inputTemplateFileForStyleCss)
File stylesCss = new File("${outputConferenceStartDirectoryName}/styles.css")
stylesCss.write(cssStyles)
log.info("Created {}", stylesCss.absolutePath)

String outputPathSpeakerImages = "${outputConferenceStartDirectoryName}/speaker/images"
String outputPathSpeakerImages = "${outputConferenceStartDirectoryName}${File.separator}rest${File.separator}speaker${File.separator}images"
def speakerImageExporter = new SpeakerImageServiceFileExporter(speakerImageServiceImpl, outputPathSpeakerImages)
String outputDir = speakerImageExporter.export()
log.info("Created {} with {} images", outputDir, speakerImageServiceImpl.images.size())

def cssStylesOld = generateStylesCssContent(conferenceConfig, inputTemplateFileForStyleCss)
File cssStylesFileOld = new File("${outputConferenceStartDirectoryName}${File.separator}rest${File.separator}styles.css")
cssStylesFileOld.write(cssStylesOld)
log.info("Created DEPRICATED {}", cssStylesFileOld.absolutePath)

def cssStyles = generateStylesCssContent(conferenceConfig, inputTemplateFileForStyleCss)
File cssStylesFile = new File("${outputConferenceStartDirectoryName}${File.separator}styles.css")
cssStylesFile.write(cssStyles)
log.info("Created {}", cssStylesFile.absolutePath)

def faviconBytes = imageResourcesJsonContent.getConferenceFavIcon()
if(faviconBytes) {
File faviconFolder = new File("${outputConferenceStartDirectoryName}${File.separator}img")
File faviconFile = new File("${faviconFolder.absolutePath}${File.separator}favicon.ico")
faviconFolder.mkdirs()
faviconFile.append(faviconBytes)
log.info("Created {}", faviconFile.absolutePath)
}
}
}

Expand All @@ -112,15 +127,19 @@ class GenerateDukecon {

private static CoreImages getImageResourcesJsonContent(String imagePath, String conferenceId) {
def images = CoreImages.builder().build()
def resourceDir = "${imagePath}/${conferenceId}"
def resourceDir = "${imagePath}${File.separator}${conferenceId}"

if(!new File(resourceDir).exists()) {
log.warn("resource {} for image-resources.json does not exist", resourceDir)
}

setFilesAsByteArray("${resourceDir}/conference", images.&setConferenceImage, "logo")
setFilesAsByteArray("${resourceDir}/favicon", images.&setConferenceFavIcon, "favicon")
setFilesAsByteArray("${resourceDir}${File.separator}conference", images.&setConferenceImage, "logo")
setFilesAsByteArray("${resourceDir}${File.separator}favicon", images.&setConferenceFavIcon, "favicon")

setFilesAsByteArray("${resourceDir}/locations", images.&setLocationImages)
setFilesAsByteArray("${resourceDir}/location-maps", images.&setLocationMapImages)
setFilesAsByteArray("${resourceDir}/languages", images.&setLanguageImages)
setFilesAsByteArray("${resourceDir}/streams", images.&setStreamImages)
setFilesAsByteArray("${resourceDir}${File.separator}locations", images.&setLocationImages)
setFilesAsByteArray("${resourceDir}${File.separator}location-maps", images.&setLocationMapImages)
setFilesAsByteArray("${resourceDir}${File.separator}languages", images.&setLanguageImages)
setFilesAsByteArray("${resourceDir}${File.separator}streams", images.&setStreamImages)

images
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,14 @@ class SpeakerImageServiceFileExporter {
def pathInFilesystem = new File(this.path)
if(!pathInFilesystem.exists())
pathInFilesystem.mkdirs()
this.service.images.forEach{ md5,image -> writeToDisk(image, this.path) }

this.service.images.forEach{ md5,image -> writeToDisk(image) }

return pathInFilesystem.absolutePath
}

void writeToDisk(SpeakerImageService.ImageWithName image, String path) {
FileOutputStream outputStream
String fileWithPath = path + File.separator + image.filename
try {
outputStream = new FileOutputStream(fileWithPath)
outputStream.write(image.content)
outputStream.flush()
} catch(Exception e) {
throw new RuntimeException("could not write file: $fileWithPath ", e)
} finally {
if(outputStream)
outputStream.close()
}
private void writeToDisk(SpeakerImageService.ImageWithName image) {
new File(this.path + File.separator + image.filename).append(image.content)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import org.junit.rules.TemporaryFolder
class ResourcesFinderTests {

@Rule
public TemporaryFolder folder = new TemporaryFolder();
public TemporaryFolder folder = new TemporaryFolder()

def filesToTest = ['1.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg']

@Before
void init() {
folder.newFolder("streams")
filesToTest.forEach { file ->
folder.newFile("streams/"+ file)
folder.newFile("streams"+ File.separator + file)
}
}

@Test
public void listFilesInClasspathFolder() {
// when
def resourcesFinder = new ResourcesFinder(folder.root.getAbsolutePath() + "/streams")
def resourcesFinder = new ResourcesFinder(folder.root.getAbsolutePath() + File.separator + "streams")

// and
def listOfFiles = resourcesFinder.getFileList()
Expand Down

0 comments on commit a77f1a4

Please sign in to comment.