Skip to content

Commit

Permalink
Revert "linted code to test ci check"
Browse files Browse the repository at this point in the history
This reverts commit 55ec853.
  • Loading branch information
LewerenzM committed Jun 12, 2024
1 parent 55ec853 commit a3e8763
Show file tree
Hide file tree
Showing 114 changed files with 2,113 additions and 3,657 deletions.
700 changes: 282 additions & 418 deletions src/main/java/org/icatproject/ids/IdsService.java

Large diffs are not rendered by default.

138 changes: 50 additions & 88 deletions src/main/java/org/icatproject/ids/Tidier.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,77 +55,57 @@ public void run() {

if (twoLevel) {
if (storageUnit == StorageUnit.DATASET) {
List<DsInfo> dsInfos = mainStorage.getDatasetsToArchive(
stopArchivingLevel, startArchivingLevel);
List<DsInfo> dsInfos = mainStorage.getDatasetsToArchive(stopArchivingLevel,
startArchivingLevel);
for (DsInfo dsInfo : dsInfos) {
StringBuilder sb = new StringBuilder(
"SELECT ds FROM Dataset ds, ds.investigation inv, inv.facility fac WHERE");
boolean andNeeded = false;
andNeeded = addNumericConstraint(sb, "ds.id",
dsInfo.getDsId(), andNeeded);
andNeeded = addStringConstraint(sb, "ds.location",
dsInfo.getDsLocation(), andNeeded);
andNeeded = addStringConstraint(sb, "ds.name",
dsInfo.getDsName(), andNeeded);

andNeeded = addNumericConstraint(sb, "inv.id",
dsInfo.getInvId(), andNeeded);
andNeeded = addStringConstraint(sb, "inv.name",
dsInfo.getInvName(), andNeeded);
andNeeded = addStringConstraint(sb, "inv.visitId",
dsInfo.getVisitId(), andNeeded);

andNeeded = addStringConstraint(sb, "fac.name",
dsInfo.getFacilityName(), andNeeded);
andNeeded = addNumericConstraint(sb, "fac.id",
dsInfo.getFacilityId(), andNeeded);
andNeeded = addNumericConstraint(sb, "ds.id", dsInfo.getDsId(), andNeeded);
andNeeded = addStringConstraint(sb, "ds.location", dsInfo.getDsLocation(), andNeeded);
andNeeded = addStringConstraint(sb, "ds.name", dsInfo.getDsName(), andNeeded);

andNeeded = addNumericConstraint(sb, "inv.id", dsInfo.getInvId(), andNeeded);
andNeeded = addStringConstraint(sb, "inv.name", dsInfo.getInvName(), andNeeded);
andNeeded = addStringConstraint(sb, "inv.visitId", dsInfo.getVisitId(), andNeeded);

andNeeded = addStringConstraint(sb, "fac.name", dsInfo.getFacilityName(), andNeeded);
andNeeded = addNumericConstraint(sb, "fac.id", dsInfo.getFacilityId(), andNeeded);

sb.append(" INCLUDE ds.investigation.facility");
try {
int low = 0;
while (true) {
String query = sb.toString() + " LIMIT "
+ low + "," + tidyBlockSize;
String query = sb.toString() + " LIMIT " + low + "," + tidyBlockSize;
List<Object> os = reader.search(query);
logger.debug(query + " returns " + os.size()
+ " datasets");
logger.debug(query + " returns " + os.size() + " datasets");
for (Object o : os) {
DatasetInfo dsInfoImpl = new DatasetInfo(
(Dataset) o);
logger.debug("Requesting archive of "
+ dsInfoImpl
+ " to recover main storage");
fsm.queue(dsInfoImpl,
DeferredOp.ARCHIVE);
DatasetInfo dsInfoImpl = new DatasetInfo((Dataset) o);
logger.debug(
"Requesting archive of " + dsInfoImpl + " to recover main storage");
fsm.queue(dsInfoImpl, DeferredOp.ARCHIVE);
}
if (os.size() < tidyBlockSize) {
break;
}
low += tidyBlockSize;
}
} catch (InternalException | IcatException_Exception
| InsufficientPrivilegesException e) {
} catch (InternalException | IcatException_Exception | InsufficientPrivilegesException e) {
// Log it and carry on
logger.error(
e.getClass() + " " + e.getMessage());
logger.error(e.getClass() + " " + e.getMessage());
}
}

} else if (storageUnit == StorageUnit.DATAFILE) {
List<DfInfo> dfInfos = mainStorage
.getDatafilesToArchive(stopArchivingLevel,
startArchivingLevel);
List<DfInfo> dfInfos = mainStorage.getDatafilesToArchive(stopArchivingLevel,
startArchivingLevel);
for (DfInfo dfInfo : dfInfos) {
StringBuilder sb = new StringBuilder(
"SELECT df FROM Datafile df WHERE");
StringBuilder sb = new StringBuilder("SELECT df FROM Datafile df WHERE");
boolean andNeeded = false;

andNeeded = addNumericConstraint(sb, "df.id",
dfInfo.getDfId(), andNeeded);
andNeeded = addStringConstraint(sb, "df.createId",
dfInfo.getCreateId(), andNeeded);
andNeeded = addStringConstraint(sb, "df.modId",
dfInfo.getModId(), andNeeded);
andNeeded = addNumericConstraint(sb, "df.id", dfInfo.getDfId(), andNeeded);
andNeeded = addStringConstraint(sb, "df.createId", dfInfo.getCreateId(), andNeeded);
andNeeded = addStringConstraint(sb, "df.modId", dfInfo.getModId(), andNeeded);
if (key != null) {
if (dfInfo.getDfLocation() != null) {
if (andNeeded) {
Expand All @@ -134,54 +114,42 @@ public void run() {
sb.append(" ");
andNeeded = true;
}
sb.append("df.location" + " LIKE '"
+ dfInfo.getDfLocation() + " %'");
sb.append("df.location" + " LIKE '" + dfInfo.getDfLocation() + " %'");
}
} else {
andNeeded = addStringConstraint(sb,
"df.location",
andNeeded = addStringConstraint(sb, "df.location",

dfInfo.getDfLocation(), andNeeded);
}
andNeeded = addStringConstraint(sb, "df.name",
dfInfo.getDfName(), andNeeded);
andNeeded = addStringConstraint(sb, "df.name", dfInfo.getDfName(), andNeeded);

sb.append(" INCLUDE df.dataset");
try {
int low = 0;
while (true) {
String query = sb.toString() + " LIMIT "
+ low + "," + tidyBlockSize;
String query = sb.toString() + " LIMIT " + low + "," + tidyBlockSize;
List<Object> os = reader.search(query);
logger.debug(query + " returns " + os.size()
+ " datafiles");
logger.debug(query + " returns " + os.size() + " datafiles");
for (Object o : os) {
Datafile df = (Datafile) o;
DatafileInfo dfInfoImpl = new DatafileInfo(
df.getId(), df.getName(),

LocationHelper.getLocation(
df.getId(),
df.getLocation()),
df.getCreateId(), df.getModId(),
df.getDataset().getId());

logger.debug("Requesting archive of "
+ dfInfoImpl
+ " to recover main storage");
fsm.queue(dfInfoImpl,
DeferredOp.ARCHIVE);
DatafileInfo dfInfoImpl = new DatafileInfo(df.getId(), df.getName(),

LocationHelper.getLocation(df.getId(), df.getLocation()), df.getCreateId(),
df.getModId(), df.getDataset().getId());


logger.debug(
"Requesting archive of " + dfInfoImpl + " to recover main storage");
fsm.queue(dfInfoImpl, DeferredOp.ARCHIVE);
}
if (os.size() < tidyBlockSize) {
break;
}
low += tidyBlockSize;
}
} catch (InternalException | IcatException_Exception
| InsufficientPrivilegesException e) {
} catch (InternalException | IcatException_Exception | InsufficientPrivilegesException e) {
// Log it and carry on
logger.error(
e.getClass() + " " + e.getMessage());
logger.error(e.getClass() + " " + e.getMessage());
}
}
}
Expand All @@ -197,8 +165,7 @@ public void run() {

private final static Logger logger = LoggerFactory.getLogger(Tidier.class);

static boolean addStringConstraint(StringBuilder sb, String var,
String value, boolean andNeeded) {
static boolean addStringConstraint(StringBuilder sb, String var, String value, boolean andNeeded) {
if (value != null) {
if (andNeeded) {
sb.append(" AND ");
Expand All @@ -211,8 +178,7 @@ static boolean addStringConstraint(StringBuilder sb, String var,
return andNeeded;
}

static boolean addNumericConstraint(StringBuilder sb, String var,
Long value, boolean andNeeded) {
static boolean addNumericConstraint(StringBuilder sb, String var, Long value, boolean andNeeded) {
if (value != null) {
if (andNeeded) {
sb.append(" AND ");
Expand All @@ -225,8 +191,7 @@ static boolean addNumericConstraint(StringBuilder sb, String var,
return andNeeded;
}

static void cleanPreparedDir(Path preparedDir, int preparedCount)
throws IOException {
static void cleanPreparedDir(Path preparedDir, int preparedCount) throws IOException {

Map<Long, Path> dateMap = new HashMap<>();
File[] files = preparedDir.toFile().listFiles();
Expand Down Expand Up @@ -286,13 +251,11 @@ public void init() {
try {

PropertyHandler propertyHandler = PropertyHandler.getInstance();
FiniteStateMachine.createInstance(reader, lockManager,
propertyHandler.getStorageUnit());
FiniteStateMachine.createInstance(reader, lockManager, propertyHandler.getStorageUnit());
this.fsm = FiniteStateMachine.getInstance();
this.fsm.init(); // if not yet initialized by IdsService do it now

sizeCheckIntervalMillis = propertyHandler
.getSizeCheckIntervalMillis();
this.fsm.init(); //if not yet initialized by IdsService do it now

sizeCheckIntervalMillis = propertyHandler.getSizeCheckIntervalMillis();
preparedCount = propertyHandler.getPreparedCount();
preparedDir = propertyHandler.getCacheDir().resolve("prepared");
Files.createDirectories(preparedDir);
Expand All @@ -310,8 +273,7 @@ public void init() {

logger.info("Tidier started");
} catch (IOException e) {
throw new RuntimeException(
"Tidier reports " + e.getClass() + " " + e.getMessage());
throw new RuntimeException("Tidier reports " + e.getClass() + " " + e.getMessage());
}

}
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/icatproject/ids/enums/RequestType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
* This enum contains all defined types of requests to this server
*/
public enum RequestType {
GETDATA, ARCHIVE, GETICATURL, GETDATAFILEIDS, GETSERVICESTATUS, GETSIZE,
GETSTATUS, ISPREPARED, ISREADONLY, ISTWOLEVEL, PREPAREDATA, PUT, RESET,
RESTORE, WRITE, DELETE
GETDATA,
ARCHIVE,
GETICATURL,
GETDATAFILEIDS,
GETSERVICESTATUS,
GETSIZE,
GETSTATUS,
ISPREPARED,
ISREADONLY,
ISTWOLEVEL,
PREPAREDATA,
PUT,
RESET,
RESTORE,
WRITE,
DELETE
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import jakarta.ws.rs.ext.Provider;

/**
* Capture any {@link org.icatproject.ids.exceptions.IdsException
* WebServiceException} thrown from {@link org.icatproject.ids.IdsService
* WebService} and generate the appropriate response code and message.
* Capture any {@link org.icatproject.ids.exceptions.IdsException WebServiceException} thrown from
* {@link org.icatproject.ids.IdsService WebService} and generate the appropriate response code and
* message.
*/
@Provider
public class IdsExceptionMapper implements ExceptionMapper<IdsException> {
Expand All @@ -23,7 +23,6 @@ public Response toResponse(IdsException e) {
gen.writeStartObject().write("code", e.getClass().getSimpleName())
.write("message", e.getShortMessage());
gen.writeEnd().close();
return Response.status(e.getHttpStatusCode()).entity(baos.toString())
.build();
return Response.status(e.getHttpStatusCode()).entity(baos.toString()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@
import org.slf4j.LoggerFactory;

@Provider
public class NotFoundExceptionMapper
implements ExceptionMapper<NotFoundException> {
public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> {

private static Logger logger = LoggerFactory
.getLogger(NotFoundExceptionMapper.class);
private static Logger logger = LoggerFactory.getLogger(NotFoundExceptionMapper.class);

@Override
public Response toResponse(NotFoundException e) {
logger.info("Processing: " + e.getClass() + " " + e.getMessage(), e);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonGenerator gen = Json.createGenerator(baos);
gen.writeStartObject().write("code", "NOT_IMPLEMENTED")
.write("message",
"Operation not implemented by this IDS server.")
.writeEnd().close();
return Response.status(Response.Status.NOT_IMPLEMENTED)
.entity(baos.toString()).build();
.write("message", "Operation not implemented by this IDS server.").writeEnd().close();
return Response.status(Response.Status.NOT_IMPLEMENTED).entity(baos.toString()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
import org.slf4j.LoggerFactory;

@Provider
public class RuntimeExceptionMapper
implements ExceptionMapper<RuntimeException> {
public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {

private final static Logger logger = LoggerFactory
.getLogger(RuntimeExceptionMapper.class);
private final static Logger logger = LoggerFactory.getLogger(RuntimeExceptionMapper.class);

@Override
public Response toResponse(RuntimeException e) {
Expand All @@ -29,9 +27,8 @@ public Response toResponse(RuntimeException e) {
baos.reset();
JsonGenerator gen = Json.createGenerator(baos);
gen.writeStartObject().write("code", "InternalException")
.write("message", e.getClass() + " " + e.getMessage())
.writeEnd().close();
return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR)
.entity(baos.toString()).build();
.write("message", e.getClass() + " " + e.getMessage()).writeEnd().close();
return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(baos.toString())
.build();
}
}
Loading

0 comments on commit a3e8763

Please sign in to comment.