Skip to content

Commit

Permalink
#213 add initial part of the business logic part2
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Oct 16, 2016
1 parent 7ae77f8 commit 7b75ebb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/alfio/manager/UploadedResourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ public boolean hasResource(int organizationId, int eventId, String name) {
return uploadedResourceRepository.hasResource(organizationId, eventId, name);
}

public UploadedResource get(String name) {
return uploadedResourceRepository.get(name);
}

public UploadedResource get(int organizationId, String name) {
return uploadedResourceRepository.get(organizationId, name);
}

public UploadedResource get(int organizationId, int eventId, String name) {
return uploadedResourceRepository.get(organizationId, eventId, name);
}


public void outputResource(String name, OutputStream out) {
SqlParameterSource param = new MapSqlParameterSource("name", name);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/alfio/repository/UploadedResourceRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ public interface UploadedResourceRepository {
})
boolean hasResource(@Bind("organizationId") int organizationId, @Bind("eventId") int eventId, @Bind("name") String name);



@Query("select name, content_size, content_type, creation_time, attributes, null as organization_id_fk, null as event_id_fk from resource_global where name = :name")
UploadedResource get(@Bind("name") String name);

@Query("select name, content_size, content_type, creation_time, attributes, organization_id_fk, null as event_id_fk from resource_organizer where organization_id_fk = :organizationId and name = :name")
UploadedResource get(@Bind("organizationId") int organizationId, @Bind("name") String name);

@Query("select name, content_size, content_type, creation_time, attributes, organization_id_fk, event_id_fk from resource_event where organization_id_fk = :organizationId and event_id_fk = :eventId and name = :name")
UploadedResource get(@Bind("organizationId") int organizationId, @Bind("eventId") int eventId, @Bind("name") String name);




@Query("select name, content_size, content_type, creation_time, attributes, null as organization_id_fk, null as event_id_fk from resource_global order by name asc")
List<UploadedResource> findAll();

Expand All @@ -55,6 +69,7 @@ public interface UploadedResourceRepository {
List<UploadedResource> findAll(@Bind("organizationId") int organizationId, @Bind("eventId") int eventId);



@Query("delete from resource_global where name = :name")
int delete(@Bind("name") String name);

Expand All @@ -65,6 +80,7 @@ public interface UploadedResourceRepository {
int delete(@Bind("organizationId") int organizationId, @Bind("eventId") int eventId, @Bind("name") String name);



@Query(type = QueryType.TEMPLATE, value = "select content from resource_global where name = :name")
String fileContentTemplate(String name);

Expand All @@ -74,6 +90,9 @@ public interface UploadedResourceRepository {
@Query(type = QueryType.TEMPLATE, value = "select content from resource_event where name = :name and organization_id_fk = :organizationId and event_id_fk = :eventId")
String fileContentTemplate(int organizationId, int eventId, String name);




@Query(type = QueryType.TEMPLATE, value = "insert into resource_global (name, content_size, content, content_type, attributes) " +
"values(?, ?, ?, ?, ?)")
String uploadTemplate(String name);
Expand All @@ -85,4 +104,5 @@ public interface UploadedResourceRepository {
@Query(type = QueryType.TEMPLATE, value = "insert into resource_event (name, organization_id_fk, event_id_fk, content_size, content, content_type, attributes) " +
"values(?, ?, ?, ?, ?, ?, ?)")
String uploadTemplate(int organizationId, int eventId, String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void testGlobal() {

Assert.assertTrue(uploadedResourceManager.hasResource("file_name.txt"));
Assert.assertEquals(1, uploadedResourceManager.findAll().size());
Assert.assertEquals(toSave.getName(), uploadedResourceManager.get("file_name.txt").getName());

ByteArrayOutputStream baos = new ByteArrayOutputStream();
uploadedResourceManager.outputResource("file_name.txt", baos);
Expand Down Expand Up @@ -140,6 +141,7 @@ public void testOrganization() {

Assert.assertTrue(uploadedResourceManager.hasResource(orgId, "file_name.txt"));
Assert.assertEquals(1, uploadedResourceManager.findAll(orgId).size());
Assert.assertEquals(toSave.getName(), uploadedResourceManager.get(orgId, "file_name.txt").getName());

ByteArrayOutputStream baos = new ByteArrayOutputStream();
uploadedResourceManager.outputResource(orgId, "file_name.txt", baos);
Expand Down Expand Up @@ -168,6 +170,7 @@ public void testEvent() {

Assert.assertTrue(uploadedResourceManager.hasResource(orgId, eventId, "file_name.txt"));
Assert.assertEquals(1, uploadedResourceManager.findAll(orgId, eventId).size());
Assert.assertEquals(toSave.getName(), uploadedResourceManager.get(orgId, eventId, "file_name.txt").getName());

ByteArrayOutputStream baos = new ByteArrayOutputStream();
uploadedResourceManager.outputResource(orgId, eventId, "file_name.txt", baos);
Expand Down

0 comments on commit 7b75ebb

Please sign in to comment.