Skip to content

Commit

Permalink
Mergin atividade 6 com passos da atividade 5 apos rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Silva committed Feb 6, 2014
2 parents 7c0c2a7 + fc93f09 commit c9f3f82
Show file tree
Hide file tree
Showing 32 changed files with 231 additions and 260 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,4 @@ target/test-reports/plain/TEST-functional-cucumber-orientations-out.txt

target/test-reports/plain/TEST-functional-cucumber-orientations.txt

target/classes
2 changes: 2 additions & 0 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ grails.project.dependency.resolution = {
plugins {
compile ":twitter4j:0.3.2"
compile ":remote-control:1.4"
compile ":codenarc:0.20"
compile ":gmetrics:0.3.1"

runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.7.1"
Expand Down
35 changes: 19 additions & 16 deletions grails-app/controllers/rgms/member/OrientationController.groovy
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
//#if($Orientation)
package rgms.member

import org.springframework.dao.DataIntegrityViolationException
import org.springframework.web.multipart.MultipartHttpServletRequest
import org.springframework.web.multipart.commons.CommonsMultipartFile
import rgms.XMLService
import rgms.authentication.User

class OrientationController {

static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
Expand All @@ -27,21 +21,29 @@ class OrientationController {
def save() {
def orientationInstance = new Orientation(params)

if(orientationInstance.orientador.name .equalsIgnoreCase(orientationInstance.orientando))
{
render(view: "create", model: [orientationInstance: orientationInstance])
flash.message = message(code: 'orientation.same.members', args: [message(code: 'orientation.label', default: 'Orientation'), orientationInstance.id])
return
if(!comparacaoOrientationComRender(orientationInstance, "create")) {
return false
}
if (!orientationInstance.save(flush: true)) {
render(view: "create", model: [orientationInstance: orientationInstance])
return
return false
}

showFlashMessage(orientationInstance.id, "show", 'default.created.message')

}

def comparacaoOrientationComRender(orientationInstance, tipoRender) {
if(orientationInstance.orientador.name.equalsIgnoreCase(orientationInstance.orientando)) {
render(view: tipoRender, model: [orientationInstance: orientationInstance])
//noinspection InvalidI18nProperty
flash.message = message(code: 'orientation.same.members', args: [message(code: 'orientation.label', default: 'Orientation'), orientationInstance.id])
return false
}
return true

}

def show = {
_processOrientation()
}
Expand All @@ -51,12 +53,14 @@ class OrientationController {
}

def showFlashMessage(Long id, String action, String code){
//noinspection InvalidI18nProperty
flash.message = message(code: code, args: [message(code: 'orientation.label', default: 'Orientation'), id])
redirect(action: action, id: id)
}

def _processOrientation()
{
//noinspection GroovyAssignabilityCheck
def orientationInstance = Orientation.get(params.id)
if (!orientationInstance) {
showFlashMessage(null, "list",'default.not.found.message')
Expand Down Expand Up @@ -98,19 +102,17 @@ class OrientationController {

def checkOrientationOrientando(Orientation orientationInstance){

if(orientationInstance.orientador.name.equalsIgnoreCase(orientationInstance.orientando)) {
render(view: "edit", model: [orientationInstance: orientationInstance])
flash.message = message(code: 'orientation.same.members', args: [message(code: 'orientation.label', default: 'Orientation'), orientationInstance.id])
if(!comparacaoOrientationComRender(orientationInstance, "edit")) {
return false
}

return true
}

def checkOrientationVersion(Orientation orientationInstance, Long version){

if (version != null) {
if (orientationInstance.version > version) {
//noinspection InvalidI18nProperty
orientationInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
[message(code: 'orientation.label', default: 'Orientation')] as Object[],
'default.orientation.checkVersion.message')
Expand All @@ -125,6 +127,7 @@ class OrientationController {
def orientationInstance = isOrientationInstance(id)

if(orientationInstance != null){
//noinspection GroovyUnusedCatchParameter
try {
orientationInstance.delete(flush: true)
showFlashMessage(id,"list",'default.deleted.message')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ class BibtexGenerateFileController {
}

def generateBibTex = {
String bibtex = ""
int numero = (params.id).toInteger()
for(publication in Publication.getAll())
{
for(member in publication.getMembers())
{
if(member.getId() == numero)
{
bibtex = bibtex + publication.generateBib() + "<br>"
render(membroPublicacoes(numero))
}

private String membroPublicacoes(int numero) {
String bibtex = ""
for (publication in Publication.getAll()) {
for (member in publication.getMembers()) {
if (member.getId() == numero) {
bibtex = bibtex + publication.generateBib() + "<br>"
break
}

}
}

render(bibtex)
return bibtex
}

def generateBibTexGroup = {
Expand All @@ -78,18 +78,6 @@ class BibtexGenerateFileController {

String teste(numero)
{
String bibtex = ""
for(publication in Publication.getAll())
{
for(member in publication.getMembers())
{
if(member.getId() == numero)
{
bibtex = bibtex + publication.generateBib() + "<br>"
break
}
}
}
return bibtex
return membroPublicacoes(numero)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ class BookChapterController {
//Member author = user?.author
//pb.sendPostFacebook(author, bookChapterInstance.toString())
//#end
//noinspection InvalidI18nProperty
flash.message = message(code: 'default.created.message', args: [message(code: 'bookChapter.label', default: 'BookChapter'), bookChapterInstance.id])
redirect(action: "show", id: bookChapterInstance.id)
}

def accessBookChapter(Long id) {
def bookChapterInstance = BookChapter.get(id)
boolean isReturned = aux.check(id, bookChapterInstance, 'bookChapter.label', 'BookChapter');
if (!isReturned) {
BookChapter bookChapterInstance = checkBook(id)
if(bookChapterInstance != null){
[bookChapterInstance: bookChapterInstance]
}
}

private BookChapter checkBook(long id) {
def bookChapterInstance = BookChapter.get(id)
//noinspection GroovyUnusedAssignment,GroovyUnusedAssignment
boolean isReturned = aux.check(id, bookChapterInstance, 'bookChapter.label', 'BookChapter')
isReturned ? bookChapterInstance : null
}

def show(Long id) {
accessBookChapter(id)
}
Expand All @@ -56,9 +63,9 @@ class BookChapterController {
}

def update(Long id, Long version) {
def bookChapterInstance = BookChapter.get(id)
boolean isReturned = aux.check(id, bookChapterInstance, 'bookChapter.label', 'BookChapter')
if (!isReturned) {

def bookChapterInstance = checkBook(id)
if (bookChapterInstance != null) {
if (version != null && bookChapterInstance.version > version) {
outdatedVersionError((BookChapter) bookChapterInstance)
} else {
Expand All @@ -68,6 +75,7 @@ class BookChapterController {
}

def outdatedVersionError(BookChapter bookChapterInstance) {
//noinspection InvalidI18nProperty
bookChapterInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
[message(code: 'bookChapter.label', default: 'BookChapter')] as Object[],
"Another user has updated this BookChapter while you were editing")
Expand All @@ -79,6 +87,7 @@ class BookChapterController {
if (!bookChapterInstance.save(flush: true)) {
render(view: "edit", model: [bookChapterInstance: bookChapterInstance])
} else {
//noinspection InvalidI18nProperty
flash.message = message(code: 'default.updated.message', args: [message(code: 'bookChapter.label', default: 'BookChapter'), bookChapterInstance.id])
redirect(action: "show", id: bookChapterInstance.id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class DissertacaoController extends ThesisOrDissertationController {
def save() {
saveThesisOrDissertation("Dissertacao", params)
}
def getDissertacaoInstance(def id)
{
def dissertacaoInstance = Dissertacao.get(id)
def getDissertacaoInstance(def id){
//noinspection GroovyAssignabilityCheck
def dissertacaoInstance = Dissertacao.get(id)
if (!dissertacaoInstance) {
flash.message = messageGenerator('default.not.found.message', id)
flash.message = messageGenerator('','default.not.found.message', id)
redirect(action: "list")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class PublicationController {
return false
}

return lerPreencherBuffer(f)
}

private boolean lerPreencherBuffer(File f) {
InputStream inputStream = request.getInputStream()
OutputStream outputStream = new FileOutputStream(f)
byte[] buffer = new byte[1024 * 10] //buffer de 10MB
Expand All @@ -106,18 +110,7 @@ class PublicationController {
flash.message = 'File already exists. Please try to use a different file name.'
return false
}
InputStream inputStream = request.getInputStream()
OutputStream outputStream = new FileOutputStream(f)
byte[] buffer = new byte[1024 * 10] //buffer de 10MB
int length

while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length)
}
outputStream.close()
inputStream.close()

return true
return lerPreencherBuffer(f)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rgms.publication

import org.apache.shiro.SecurityUtils
import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.springframework.dao.DataIntegrityViolationException
import rgms.member.Member

Expand All @@ -14,16 +13,19 @@ class ThesisOrDissertationController {
def listThesisOrDissertation(String thesisOrDissertation, params) {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
if (thesisOrDissertation == "Tese") {
//noinspection GroovyAssignabilityCheck
[teseInstanceList: Tese.list(params), teseInstanceTotal: Tese.count()]
} else if (thesisOrDissertation == "Dissertacao") {
//noinspection GroovyAssignabilityCheck
[dissertacaoInstanceList: Dissertacao.list(params), dissertacaoInstanceTotal: Dissertacao.count()]
}
}

def createThesisOrDissertation(String thesisOrDissertation, params) {
//noinspection GroovyAssignabilityCheck
def instance = getClassByName(thesisOrDissertation).newInstance(params)
//#if($contextualInformation)
def user = PublicationController.addAuthor(instance)
def user = PublicationController.addAuthor(instance as Publication)
if (user && !user.university.isEmpty()){
instance.school = user.university
}
Expand All @@ -32,20 +34,23 @@ class ThesisOrDissertationController {
}

def saveThesisOrDissertation(String thesisOrDissertation, params) {
//noinspection GroovyAssignabilityCheck
def instance = getClassByName(thesisOrDissertation).newInstance(params)
PublicationController pb = new PublicationController()
def duplicated
if (thesisOrDissertation == "Tese") {
//noinspection GroovyAssignabilityCheck
duplicated = Tese.findByTitle(params.title)
} else if (thesisOrDissertation == "Dissertacao") {
//noinspection GroovyAssignabilityCheck
duplicated = Dissertacao.findByTitle(params.title)
}
if (duplicated) {
messageGenerator(thesisOrDissertation, 'tese.duplicatetitle.failure', instance.id)
render(view: "create", model: [instance: instance])
return
}
if (!pb.upload(instance) || !instance.save(flush: true)) {
if (!pb.upload(instance as Publication) || !instance.save(flush: true)) {
render(view: "create", model: [instance: instance])
return
}
Expand All @@ -67,16 +72,14 @@ class ThesisOrDissertationController {
}

def updateThesisOrDissertation(String thesisOrDissertation, params) {
def instance = getClassByName(thesisOrDissertation).get(params.id)
if (!instance) {
messageGenerator(thesisOrDissertation, 'default.not.found.message', params.id)
redirect(action: "list")
return
}
def instance = getThesisOrDissertationControllerInstance(thesisOrDissertation,params)
if(instance == null) return
if (params.version) {
def version = params.version.toLong()
if (instance.version > version) {
//noinspection GroovyUnusedAssignment
def lower = thesisOrDissertation.toLowerCase()
//noinspection InvalidI18nProperty
instance.errors.rejectValue("version", "default.optimistic.locking.failure",
[message(code: '${lower}.label', default: thesisOrDissertation)] as Object[],
messageGenerator(thesisOrDissertation, "default.optimistic.locking.failure", params.id))
Expand All @@ -98,24 +101,29 @@ class ThesisOrDissertationController {
}

def deleteThesisOrDissertation(String thesisOrDissertation, params) {
def instance = getClassByName(thesisOrDissertation).get(params.id)
if (!instance) {
messageGenerator(thesisOrDissertation, 'default.not.found.message', params.id)
redirect(action: "list")
return
}
def instance = getThesisOrDissertationControllerInstance(thesisOrDissertation, params)
if(instance == null) return
try {
instance.removeFromPublications()
instance.delete(flush: true)
messageGenerator(thesisOrDissertation, 'default.deleted.message', instance.id)
redirect(action: "list")
}
catch (DataIntegrityViolationException e) {
catch (DataIntegrityViolationException ignored) {
messageGenerator(thesisOrDissertation, 'default.not.deleted.message', instance.id)
redirect(action: "show", id: params.id)
}
}

def getThesisOrDissertationControllerInstance(String thesisOrDissertation, params) {
def instance = getClassByName(thesisOrDissertation).get(params.id)
if (!instance) {
messageGenerator(thesisOrDissertation, 'default.not.found.message', params.id)
redirect(action: "list")
}
return instance
}

def getClassByName(String thesisOrDissertation) {
Thread.currentThread().contextClassLoader.loadClass("rgms.publication.${thesisOrDissertation}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class XMLController {
return
}

private Closure saveBookChapters = {
public Closure saveBookChapters = {
Node xmlFile ->
XMLService.createBooksChapters(xmlFile)
}
Expand Down
Loading

0 comments on commit c9f3f82

Please sign in to comment.