Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Jan 25, 2013
1 parent 51e2482 commit 35ca356
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
27 changes: 14 additions & 13 deletions src/main/java/org/fcrepo/lily/AbstractResource.java
Expand Up @@ -15,9 +15,10 @@

public abstract class AbstractResource {

static final String FNS = "fedora";
static final QName fedora = new QName(FNS, "fedora");
static final QName label = new QName(FNS, "label");
static final String fedoraNamespace = "fedora";
static final QName fedoraRecordTypeName = new QName(fedoraNamespace,
"fedora");
static final QName label = new QName(fedoraNamespace, "label");

static public Repository repo = null;
static public LilyClient client = null;
Expand All @@ -29,7 +30,7 @@ public abstract class AbstractResource {
}

AbstractResource(LilyClient cl) {
this.client = cl;
client = cl;
}

@PostConstruct
Expand All @@ -38,17 +39,17 @@ void initFedoraRecordType() throws RepositoryException,
logger.debug("Trying to retrieve Fedora RecordType");
TypeManager tm = getRepo().getTypeManager();
try {
tm.getRecordTypeByName(fedora, 1L);
tm.getRecordTypeByName(fedoraRecordTypeName, 1L);
logger.debug("Retrieved Fedora RecordType");
} catch (RecordTypeNotFoundException e) {
logger.debug("Creating Fedora RecordType");
RecordType fedoraRecordType = tm.recordTypeBuilder().name(fedora)
.fieldEntry().defineField().name(label)
.type(new StringValueType()).createOrUpdate().add()
.createOrUpdate();
RecordType fedoraRecordType = tm.recordTypeBuilder()
.name(fedoraRecordTypeName).fieldEntry().defineField()
.name(label).type(new StringValueType()).createOrUpdate()
.add().createOrUpdate();
tm.createOrUpdateRecordType(fedoraRecordType);
logger.debug("Created Fedora RecordType");
}
logger.debug("Created Fedora RecordType");

}

public static Repository getRepo() {
Expand All @@ -64,8 +65,8 @@ public static LilyClient getClient() {
return client;
}

public static void setClient(LilyClient client) {
AbstractResource.client = client;
public static void setClient(LilyClient cl) {
client = cl;
}

}
13 changes: 3 additions & 10 deletions src/main/java/org/fcrepo/lily/FedoraObjects.java
Expand Up @@ -10,8 +10,6 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import org.lilyproject.repository.api.IdGenerator;
import org.lilyproject.repository.api.QName;
import org.lilyproject.repository.api.Record;
import org.lilyproject.repository.api.RecordId;
import org.lilyproject.repository.api.Repository;
Expand All @@ -22,20 +20,16 @@
@Path("/objects")
public class FedoraObjects extends AbstractResource {

IdGeneratorImpl idGenerator = (IdGeneratorImpl) client.getRepository()
.getIdGenerator();
UserRecordIdFactory userRecordIdFactory = new UserRecordIdFactory();

Repository repo = getRepo();
IdGeneratorImpl idGenerator = (IdGeneratorImpl) repo.getIdGenerator();
UserRecordIdFactory userRecordIdFactory = new UserRecordIdFactory();

@Path("/{pid}")
@GET
public Response getObject(@PathParam("pid") final String pid)
throws RepositoryException, InterruptedException {
RecordId pidRecId = userRecordIdFactory.fromString(pid, idGenerator);

Record rec = repo.read(pidRecId, label);

return Response.ok((String) rec.getField(label)).build();
}

Expand All @@ -45,9 +39,8 @@ public Response addObject(@PathParam("pid") final String pid,
@QueryParam("label") @DefaultValue("test") final String objLabel)
throws RepositoryException, InterruptedException {

repo.recordBuilder().recordType(fedora).id(pid).field(label, objLabel)
repo.recordBuilder().recordType(fedoraRecordTypeName).id(pid).field(label, objLabel)
.createOrUpdate();

return Response.created(URI.create(pid)).build();
}
}

0 comments on commit 35ca356

Please sign in to comment.